|
|
Title | Use VBA code to add and remove comments in Excel cells |
Description | This example shows how to use VBA code to add and remove comments in Excel cells |
Keywords | VBA, Excel, comment, remark |
Categories | Office |
|
|
To make a comment, use a Cell's Comment object. First if the Cell does not have a Comment object, usethe Cells AddComment method to create one. Then use the Comment object's Text method to assign text to it.
|
|
' Add a comment.
Private Sub cmdMakeComment_Click()
Dim rng As Range
Set rng = ActiveSheet.Cells(4, 4)
If rng.Comment Is Nothing Then rng.AddComment
rng.Comment.Text "It is now " & Format(Now)
End Sub
|
|
To remove a comment, call the Comment object's Delete method.
|
|
' Remove a comment.
Private Sub cmdRemoveComment_Click()
Dim rng As Range
Set rng = ActiveSheet.Cells(4, 4)
If Not (rng.Comment Is Nothing) Then rng.Comment.Delete
End Sub
|
|
|
|
|
|