Home

Creating Comments in VBA

 

Description

A comment is a piece of text in code that would not be considered when reading your code. As such, a comment can be written any way you want.

In the Visual Basic language, the line that contains a comment can start with a single quote. Here is an example:

' This line will not be considered as part of the code

Alternatively, you can start a comment with the Rem keyword. Anything on the right side of rem, Rem, or REM would not be read. Here is an example:

' This line will not be considered as part of the code
Rem I can write anything I want on this line

Comments are very useful and you are strongly suggested to use them regularly.

The code that was generated in our Practical Learning section contains a few lines of comment:

Sub Exercise1()
'
' Exercise1 Macro
'

'
    ActiveCell.FormulaR1C1 = "=2"
End Sub

 

 

 

 

Home Copyright © 2009-2016, FunctionX, Inc. Next