How to use Rem statement in VBA?

In VBA (Visual Basic for Applications), the Rem statement is used for adding comments to your code. Comments are pieces of text that are ignored by the compiler and do not affect the execution of your program. They are mainly used for documentation purposes, to explain what the code is doing, which can be especially helpful for others reading your code or for you when you come back to your code after some time.

Here’s how you can use the Rem statement in VBA:

Basic Usage

Simply type Rem followed by your comment. For example

Rem This is a comment

Inline Comments

You can also place Rem inline with other code. For example:

x = x + 1   Rem Increment x

Comments for Documentation

Use comments to explain complex logic, to describe the purpose of variables, or to provide instructions. For example:

' Calculate the sum of two numbers
' and store the result in sum
sum = number1 + number2

Remember that while comments are essential for making your code understandable, over-commenting or stating the obvious can sometimes make the code more cluttered. It’s a good practice to strike a balance.

Unlock Your Potential


Basic - Advanced


Access Basic - Advanced

Power BI

Power BI Basic - Advanced

Help us grow the project

Leave a Reply

Your email address will not be published. Required fields are marked *