Assign the comment to an Object then test the Object. Here's an example from Microsoft:
Sub Has_Comment() Dim mycomment As Object Set mycomment = ActiveCell.Comment If mycomment Is Nothing Then MsgBox "no comment in cell" Else MsgBox mycomment.Text End If End Sub
I have this as a function which returns true or false if the nominated cell has a comment, like this:
Public Function HasComment(ByRef rng As Excel.Range) As Boolean On Error Resume Next Dim cmt As Excel.Comment Set cmt = rng.Comment If Not cmt Is Nothing Then HasComment = True End If End Function
Regards - Marcus
You can also use Goto (F5), Special, Comments to select all comments on a sheet. Which, when I record it comes up as a single line in VBA
Selection.SpecialCells(xlCellTypeComments).Select
You can probably automate from there.
Regards, Alex J
Hi,
Or you could make a function out of it...
Public Function HasComment(rngRef As Range) As Boolean On Error Resume Next HasComment = CBool(Len(rngRef.Comment.Text))End Function