Type an apostrophe (') and VBA ignores the rest of the line. Comments turn green and can sit on their own line or after code, as in Range("A1").Value = 0 ' reset the counter.
To comment out several lines, select them and click Comment Block on the Edit toolbar (View → Toolbars → Edit); Uncomment Block reverses it. There’s no default shortcut, but you can make one by copying the buttons onto a toolbar with & in their names.
Give each comment line its own apostrophe. A space and underscore at the end of a comment line carries the comment onto the next line, which can hide working code by accident.
Rem also starts a comment, but only as the first word of a statement, so the apostrophe is the usual choice.
Change the comment colour under Tools → Options → Editor Format → Comment Text.
Once you start writing VBA codes, there’s an important thing that you need to learn along with that, and that’s using COMMENTS in your VBA codes.
The point is: using VBA COMMENTS is quite easy and simple; the only thing you need to learn is to do it effectively.
So today, I’ll be sharing with you all the details about using comments in VBA and all the options related to them.
What is a VBA Comment
A VBA COMMENT is a green line of text that helps you to describe the written code (green is the default color). In simple words, a comment is a line of text which is not a code and VBA ignores it while executing the code. It’s a good practice (I’d say one of the best) to add comments in your VBA codes.
(Video) Understanding VBA Comments

Advantages of using a Comment
As I said, commenting in a VBA code is one of the best practices, and there are a few benefits that come with it.
- Helps you to Document your Work: You can use a comment to describe how code works, which can help you or any other user recall it easily in the future.
- Track the Changes: If some codes need to be changed frequently, you can use comments to track or record changes within the code.
- Describe a Function Procedure: When you write a procedure, you can add a comment at the start to describe the purpose of this procedure and how it works.
- Describe a Variable: Variables are one of the most important things that you need to use while writing a VBA code, and you can use a comment to describe a variable.
- Debug Your Code: You can use VBA comments to debug the code by converting code lines into comments for testing.
Add a Comment in a VBA Code
Steps you need to follow to add a comment in a VBA code:
- First, click on the line where you want to insert the comment.
- After that, type an APOSTROPHE (‘) using your keyboard.
- Next, type the comment that you want to add to the code.
- In the end, hit Enter to move to the new line, and the comment will turn green.

The moment you do this, the entire line will turn green, which means that the line is a comment now.
Look at the below code, where I have used a comment to add a description of the procedure.
Sub ClearOldData()
' This macro clears the data from Sheet1, but keeps the headers in row 1
Worksheets("Sheet1").Rows("2:1000").ClearContents
End Sub
You simply need to add an apostrophe before a line to turn it into a comment, and VBA will ignore it while executing the code.
Use the Comment/UnComment Button from the Toolbar
The second method is to use the Comment Block button from the Edit toolbar. This button simply adds an apostrophe at the start of the line. If you don’t see the Edit toolbar, go to View ➜ Toolbars ➜ Edit.
To use this button, first of all, you need to select the line of the code and then click on the button.

Next to the Comment Block button, there’s one more button, “Uncomment Block”, which you can use to uncomment a line (This button simply removes the apostrophe from the line of the code).
Enter a Multi-Line VBA Comment
There could be a situation where you need to enter a comment in multiple lines, like a block of the comments.
But here is one thing which you need to note down: every line of comment needs to start with an apostrophe, so if you want to add multiple lines of comments, every line should have an APOSTROPHE.
The easiest way is to select all the lines and then use the Comment Block button from the toolbar, or you can also add an APOSTROPHE at the start of each line.

The moment you click the Comment Block button, it will convert all the lines into a multi-line comment block.

Update: There’s one thing that I have discovered recently: if you have a block of comment lines (continuous), you can use a line continuation character (an underscore that must be immediately preceded by a space) at the end of a comment line to carry the comment on to the next line.

In the above example, I have used an apostrophe only at the start of the first line of the comment, the other two lines don’t have an apostrophe.
But I have used the line continuation character to give a line break at the end of the first line and the second line.
Use the “REM” Keyword to Insert a Comment in VBA
This is the third way to insert a comment into a VBA code. Well, this is not a popular way, but still, you can use it.
So instead of using an apostrophe, you can use the keyword REM at the start of a comment line, followed by a space.
REM stands for remarks.

Now, in the above example, I have used “REM” at the start of the line and then the comment text. But there’s no button to add REM; you have to type it. Also, unlike the apostrophe, REM can’t simply follow code on the same line: you need a colon before it, like x = 10: Rem set the value.
Comments while Recording a Macro with Macro Recorder
When you record a macro code using the macro recorder, you get an option to add a description before you record it.
So when you open the record macro dialog box, there is a “Description” input box where you can add your comment and then start recording.

And when you open the VBE to see the recorded code, you can see the description that you have added as a comment.
When you add a comment while recording a macro, VBA adds a few apostrophes as blank comments.

Enter a Comment in the Same Line
This is a quite smart way to use a comment in the same line where you have written code.
In the below example you can see that I have three lines of code, where I have added comments after each line to describe it.

So once you complete a line of code, you can enter an apostrophe and a comment after it in the same line. Just note that an apostrophe inside double quotes is part of the text, not the start of a comment.
Shortcut Key to Add a Comment
Truly speaking, there’s no default keyboard shortcut to insert a comment.
But thanks to Gaurav, I have found a way to create a shortcut key to insert an apostrophe.
Follow the below steps:
- First of all, right-click on the toolbar and then click on the Customize option.

- In the Customize dialog box, go to the Commands tab ➜ Edit ➜ select Comment Block, and drag it to the toolbar.

- After that, right-click on the Comment Block icon on the toolbar, and in the Name box, enter “&” before the name. So it should be like “&Comment Block”.

- Now, again right-click on the button, select “Image and Text”, and after that, close the Customize dialog box and come back to the Visual Basic Editor.

Now you can convert a line into a comment by using the shortcut key Alt + C.
And if you want to create a shortcut key for the Uncomment Block button, you can simply use the above steps to add it to the toolbar with “&Uncomment Block” as the name, and the shortcut key for it will be Alt + U.
Change the Format of the Comment
VBA gives you an option to change the format of the comment if you want to do so. From Tools ➜ Options ➜ Editor Format, click on “Comment Text” in the Code Colors list and choose the colors you want.

As you can see, I have changed the color of the comment text from green to blue. Now all the comments which I have in the code window are in blue color.

Quick Tips for using VBA Comments
- Consistent Comment Style: Use a consistent style for your comments. This includes using consistent structure and words, which makes comments easier to read and understand.
- Keep Comments Up-to-Date: Update or remove comments as you change your code. Outdated comments can be more misleading than no comments at all.
- Utilize Conditional Compilation: You can use conditional compilation statements to include or exclude code blocks for debugging or testing. This can be more flexible than simple comments for temporarily disabling code.
Here’s how conditional compilation looks. Set the constant to False when you don’t need the debug lines any more, and VBA skips them without you commenting them out one by one:
#Const DebugMode = True
Sub ProcessData()
#If DebugMode Then
Debug.Print "Started at " & Now
#End If
Range("A1").Value = "Done"
End Sub
Wrap Up
The goal of comments in VBA is to make your code more understandable to other users and to you in the future. Use them wisely, and your future maintenance tasks will be much easier.
Frequently Asked Questions
Is there a block comment in VBA like /* */ in other languages?
No. Every comment line needs its own apostrophe (or a line continuation character at the end of the line before). The Comment Block button is the quickest way to comment out several lines at once.
Do comments slow down a macro?
No. VBA ignores comments when it runs the code, so you can add as many as you need.
Why is my comment not turning green?
Check that you typed a straight apostrophe (‘), not a curly quote copied from a web page or a document. Also, if the apostrophe is inside double quotes, it’s part of the text. And if you have changed the Comment Text color in the options, comments show in that color instead.
Written by
Puneet Gogia
Microsoft MVP — Excel · Founder, Excel Champs
Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.