Add Comments To A Cell

You can add comments to any cell in a worksheet using the AddComment method with the Range object. Comments are great methods for adding extra information about the value in a cell, such as how it was calculated, who provided the information, and so on. Using the AddComment method is basically the same as clicking InsertOComment within Excel. The biggest difference is that by default when you create a comment in Excel, the name of the person creating the comment is always added to the top of the comment. When you create a comment using the AddComment method, only the text you provide is added to the comment.

When you add a comment to a cell, Excel typically places a small red triangle in the upper-right corner of the cell to indicate that the cell contains a comment. You can view the comment in the cell by dragging the cursor across the cell.

To add a comment to a cell, you need to specify the range of the cell to contain the comment, the AddComment method, and the comment to add to the cell for example:

Cells(3,3).AddComment "Sample Comment Text"

You can only place a comment in one cell at a time using the AddComment method. If you want to add the same comment to multiple cells, you can use a looping statement, such as a For Next loop to cycle through the range of cells to receive the comment.

If you attempt to add a comment to a cell that already contains a comment, Excel returns an error message. To avoid potential errors, you can use the ClearComments method to clear any existing comments so that comments can be added to the specified cell. When you use this method, if the specified cell does not contain any comments the ClearComments method is ignored. You use the method as shown in this example: Cells(3,3). ClearComments

ADD COMMENTS TO A CELL

ADD COMMENTS TO A CELL

'-n Create a new subroutine.

0 Type Dim SalesLocal As String, replacing SalesLocal with the name of the string variable.

0 Type Cells(N,2).ClearComments, replacing Cells(N,2) with the reference to the cell to clear.

'-n Create a new subroutine.

Note: See Chapter 3 for information on creating subroutines.

0 Type Dim SalesLocal As String, replacing SalesLocal with the name of the string variable.

< Type For N = 3 To 16, replacing 3 and 16 with the numbers indicating the range of cells.

Type SalesLocal = Cells(N,1).Text, replacing Cells(N,1) with the range containing the text string for the comment.

0 Type Cells(N,2).ClearComments, replacing Cells(N,2) with the reference to the cell to clear.

0 -1

Post a comment