How to Comment a Block of Lines in VBA

This is one of the most common questions developers starting their journey to learning VBA ask. In VBA, how do I comment a block of lines at once? Comment blocks are a fundamental feature of any programming language, but it’s not enabled by default in VBA.

To enable VBA comment blocks, you have to configure your Visual Basic Editor (VBE).


Enabling the VBA Edit Toolbar

  1. Open your Visual Basic Editor (Alt+F11)
  2. Click View
  3. Click Toolbars
  4. Check the box beside Edit.

VBA Edit Toolbar


Navigating the Edit Toolbar

Once you enable the Edit Toolbar, new buttons for Comment Block and Uncomment Block will appear.

Comment and Uncomment Buttons

You can drag this toolbar wherever you want in your VBE. I like mine docked beside my Debug Toolbar.


Commenting Blocks of Lines

Once you’ve made it this far, you can comment blocks of VBA code by highlighting the lines and selecting the “Comment Block” button. It’ll look something like this:

VBA Comment Block Example


Make powerful macros with our free VBA Developer Kit

It’s easy to copy and paste a macro like this, but it’s harder make one on your own. To help you make macros like this, we built a free VBA Developer Kit and wrote the Big Book of Excel VBA Macros full of hundreds of pre-built macros to help you master file I/O, arrays, strings and more - grab your free copy below.

I'll take a free VBA Developer Kit

Closing Thoughts

Commenting blocks of code in VBA is a necessary skill for building and debugging your macros. In this VBA tutorial I showed you how to enable one of the most important toolbars you can have in VBA. I’m still shocked that this toolbar isn’t visible by default, but that’s okay. Now it is!

That’s all for this tutorial. When you’re ready to take your VBA to the next level, subscribe using the form below.