How To Comment Out In VBA 

Commenting is an essential practice when working with Visual Basic for Applications (VBA) code. By adding comments, programmers can enhance the clarity, maintainability, and functionality of their code. In VBA, comments serve as annotations or explanatory notes that are ignored by the compiler but provide valuable insights to other developers or the future self. This article aims to shed light on the significance of commenting and provide practical guidance on how to comment out code effectively in VBA. 

In this tutorial, we will learn how to add comments in the following VBA code. 

Method 1 – Use Of Apostrophe 

Step 1 – Launch Excel And Open VBA Editor 

  • Double-click on the Excel file. 
  • Go to the Developer Tab under Code Group and click on the Visual Basic button. 
  • Or use the shortcut key ALT + F11 to open the VBA editor. 

Step 2 – Type Your Code 

  • Type your VBA code. 

Step 3 – Add A Comment 

  • The comment can be added into a VBA code by typing Apostrophe followed by the comment for the user to understand the purpose of the code. 
  • Note that when we press enter, the font color of the comment changes to green. 

Method 2 – Use Of Comment Option In VBA Editor 

Step 1 – Type Your Code & Add A Line 

  • Type your VBA code and comment into it. 

Step 2 – Open Edit Toolbar 

  • To open the edit toolbar, go to the View menu
  • Move your mouse over the Toolbar option. 
  • Select Edit. 

Step 3 – Press Comment Block Button 

  • Place your cursor over the line & press the comment block button. 
  • Line will be converted into a comment.