When writing macro code in the Visual Basic Editor (VBE) of Microsoft Office applications it is often useful to add comments into the code to allow other users a better understanding of the program. This can be done by placing an apostrophe “ ‘ “ at the start of the comment line that we want the program to ignore. Alternatively, the same can be achieved by writing “Rem” in front of the line which is short for remark. The comment section in the code will then be coloured green to distinguish it from the rest of the code as per the following screenshot.
To quickly turn several lines of text into a comment we can use the “Comment Block” or “Uncomment Block” buttons Microsoft provides. These buttons will add or remove an apostrophe to every single line of a highlighted text which makes it much quicker to create a comment that extends over say 100 lines. Unfortunately, these buttons are not displayed by default and have to be added to the toolbar before they can be used. To do this, right-click the toolbar in the Visual Basic Editor and click “Customize”. Then select the “Edit” category and drag the buttons “Comment Block” or “Uncomment Block” to the toolbar: