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

Write better macros in half the time
I see people struggling with Excel every day and I want to help. That's why I'm giving away my personal macro library for free. This powerful gift lets you automatically import all my macros directly into your spreadsheet with just one click.

Show me how I can improve my VBA skills for free

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!

If you have more questions, leave a comment or reach out to me through my VBA Consulting page and I’ll be happy to help.

If you get a chance, please stop by my Excel Add-ins page for some great products. This is my primary source of blog revenue and the money I receive from sales helps pay to keep this website online and accessible for all to learn.

To share the skill you just learned with others, post this article on Twitter and Facebook. Sharing on social media is how I’m able to reach and teach more people about the awesome power of VBA.

I want to thank all my readers who have already subscribed to my email list and I encourage you to go ahead and subscribe if you haven’t done so. You’ll love the freebies and the fun VBA content I send your way!