Choose your language

VBA Code Comments


Commenting on a code means inserting information inside the VBE that will not be executed (the information is used for guidance only).

This practice has some advantages:

To comment a code just use a simple apostrophe symbol. Everything that comes after the ' sign will be considered a comment:

    'This is a comment

We can also apply it to parts of the code to temporarily disable them:

Sub Comment()

    'MsgBox "This will not run"
    MsgBox "But this will run"

End Sub

When executing, the following text box should appear:

VBA Comment

A comment may also be inserted into the same line after a code that will be executed.

Sub CommentAfter()

    MsgBox "This will be shown" 'And this comment will not interfere

End Sub

After the apostrophe, the rest of the line will become comment.


Commenting on a Code Block

Edit Tab

With the Edit Toolbar you can insert and remove comment blocks, just underline the code and use the buttons: Comment block and Uncomment block .

    'Sub CommentBlock()
    '
    '    MsgBox "This will not be shown" 'And this comment will not interfere
    '
    'End Sub

To add the Edit Toolbar in VBE go to: View $\rightarrow$ Toolbars $\rightarrow$ Edit.


Important Shortcuts in VBA Excel

Some shortcuts that will help save time:

Shortcuts that will only work in the VBE environment:



SuperExcelVBA.com is learning website. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. All Rights Reserved.

Excel ® is a registered trademark of the Microsoft Corporation.

© 2019 SuperExcelVBA | ABOUT

Protected by Copyscape