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


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 Google+, 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!


Get wellsrPRO for Free

Get these macros delivered right to your spreadsheet for free

Access tutorials and import my macros without ever leaving Excel

Show me - It's free

About Ryan Wells


Ryan Wells

Ryan Wells is a Nuclear Engineer and professional VBA Developer. He is the lead developer of several VBA applications, including PDF VBA - a leading Excel Add-in for exporting Excel Objects, like charts and tables, to PDFs. Discover more of his popular Excel Add-ins, including Mouse To Macro and CF Shapes, at his dedicated Excel Add-ins page.