Questions And Answers

More Tutorials

VBA Comments

Apostrophe Comments

A comment is marked by an apostrophe ('), and ignored when the code executes. Comments help explain your code to future readers, including yourself.

Since all lines starting with a comment are ignored, they can also be used to prevent code from executing (while you debug or refactor). Placing an apostrophe ' before your code turns it into a comment. (This is called commenting out the line.)

Sub InlineDocumentation()
 'Comments start with an "'"
 'They can be place before a line of code, which prevents the line from executing
 'Debug.Print "Hello World"
 'They can also be placed after a statement
 'The statement still executes, until the compiler arrives at the comment
 Debug.Print "Hello World" 'Prints a welcome message
'Comments can have 0 indention....
 '... or as much as needed
 '''' Comments can contain multiple apostrophes ''''
 'Comments can span lines (using line continuations) _
 but this can make for hard to read code
 'If you need to have mult-line comments, it is often easier to
 'use an apostrophe on each line
 'The continued statement syntax (:) is treated as part of the comment, so
 'it is not possible to place an executable statement after a comment
 'This won't run : Debug.Print "Hello World"
End Sub
'Comments can appear inside or outside a procedure


In this page (written and validated by ) you learned about VBA Comments . What's Next? If you are interested in completing VBA tutorial, your next topic will be learning about: VBA REM Comments.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.