Comments – Adding or Deleting

Working With Comments

Just like when working in Excel, you can also add comments to cells through VBA. Following is some code to work with comments.


Determine if comment is there and print to MsgBox

[sourcecode language=”vb” light=”true” wraplines=”false” gutter=”false”]
Sub Comments()
If Not Range("A1").Comment Is Nothing Then _
MsgBox Range("A1").Comment.Text ‘Print comment to message box
End Sub
[/sourcecode]


Add Comment to a cell

[sourcecode language=”vb” light=”true” wraplines=”false” gutter=”false”]
Sub AddComment() ‘Add comment to a cell
Range("B2").AddComment "Joe is cool"
End Sub
[/sourcecode]