Add comments to your VBA code – How to

Add comments to your VBA code – How to

Add comments to your VBA code - How to

This quick how to tip shows you how to add comments to your VBA code.

Add comments to your VBA code

VBA is short for Visual Basic for Applications. Overall, it is the coding language for Office apps.

To make your code more readable, we suggest placing comments in your code. The image below illustrates the two methods for placing a comment in VBA. In old versions of BASIC, they also referred to it as a remark.

Add comments - Code listing showing comments in VBA code
Partial code listing showing the two methods for displaying comments in VBA.

So, there are two ways to add comments in VBA.

  1. Firstly, you can use the Rem statement to add a comment in VBA. Keep in mind, you use Rem for single line remarks. You cannot use Rem on the same line as other VBA code.
  2. Secondly, the apostrophe (‘) starts a comment string in VBA. It is the shortcut method. Also, as you see from the above image, it is also our preferred method. In addition, you can use the apostrophe on a single line. Or, on the same line as your code.

By the way, Rem is short for Remark. It comes from the original BASIC language.

That is all to it. Enjoy!


Related


Education home  Excel Effects home