Comments
How to comment and uncomment code in VBA. Or add comments to code and formulas.
VBA using the keyboard
Press Alt + F11 to display the VBA Editor.
To add a comment type a single quote ’ either at the start of the line or after your code.
Everything after the quote but before the end of the line will be treated as a comment.
The single quote can be used to comment out a line or part of a line of code.
VBA using the User Interface
Press Alt + F11 to display the VBA Editor.
If the Edit menu is not displayed, right click on the toolbar and select Edit.
The edit toolbar will be displayed.
It has the Comment Block and Uncomment Block icons.
Hovering the mouse over the icon will show its name.
To comment out a block of code, select the code and then click on the Comment Block icon.
To uncomment a block of code, select the rows and then click on the Uncomment Block icon.
Excel formula
A note can be added to a cell by right clicking on a cell and choosing New Note.
The presence of a note attached to the cell is indicated by a red triangle in the top right corner of the cell.
Hovering over the cell will show the note.
A note can be inserted directly into a formula by using the N function.
When a string is used as the argument for the N function, it returns a zero.
To add a note, add the N function to the end of the formula.
=A4+B4+N("A note in the formula")
The formula will interpreted as
=A4+B4+0
Data Validation
Finally,Data Validation can be used. It shouldn’t be used too frequently as it is very intrusive in the user interface. Imagine every cell that you click on showing a message.
It is best used on cells where the user has to enter parameters.
Select a cell or range of cells.
Navigate to the Data menu and click on the Data Validation icon.
The Data Validation dialog will be displayed.
On the Settings tab, set the Allow dropdown to Any value.
Click on the Input Message tab.
Tick the Show input message when cell is selected tick box.
Enter a Title and an Input message.
Click on the OK button.
The Title and Input Message will be displayed when the cell is selected.