Commenting a block of code in VBA

One way is to manually place an apostrophe at the start of every line in the block.

A much easier way (I just found out today) is:

  • Go to View-Toolbars-Customise
  • Select the Command tab
  • Select the Edit Category on the left
  • Drag the “Comment Block” and “Uncomment Block” icons onto your toolbar.

Now you can comment (or uncomment) as many lines as you like with a single click.

This entry was posted in Excel, VBA and tagged , , . Bookmark the permalink.

9 Responses to Commenting a block of code in VBA

  1. Colin Legg says:

    The comment block buttons are a great tip, Doug.

    In my own set-up I’ve gone a step further and have hotkeys for commenting / uncommenting code blocks. One could code this oneself, but I’m a big fan of MZ-Tools which lets you set up hotkeys under Tools > MZ-Tools > Options > Shortcuts. For comment block I use CTRL+K and for uncomment block I use CTRL+U, to partially match the shortcuts in Visual Studio.

    Liked by 2 people

  2. Fábio says:

    Just write click on the toolbar and set Edit

    Liked by 2 people

  3. dougaj4 says:

    Colin – Thanks, I’ll have a look (I’m already an MZ-Tools user).

    Fabio – yes that will work as well.

    Like

  4. Rosss says:

    wow, you just found this out to day!!! its amazing what we miss. Hope your good mate.
    Ross

    Like

    • dougaj4 says:

      Hi Ross, there are probably quite a few basic things like that I don’t know.

      I blame too many years spent persevering with Lotus 123 🙂

      Like

  5. Tanay Chourasia says:

    This was very helpful. It’s surprising it’s not enabled by default.

    Like

  6. OliviaHoros says:

    Not the answer you re looking for? Browse other questions tagged vba comments or ask your own question .

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.