Test for comment in cell
fCellHasComment = Not Cell.Comment Is Nothing
or
Dim cm as Comment
Set cm = cell.comment
fCellHasComment = Not cm Is Nothing
but looking at your code what happens if more than one cell in the range has
the value of lngStoreNumber, and some of these cells have comments and some
don't...
Regards,
Peter T
"Ken Warthen" wrote in message
...
I have a routine that search for a given number in a range on worksheet.
If
the given number if found I want to test for a comment associated with the
found cell. My code is returning true for any given number so something
is
wrong, but I can't seem to figure it out. If anyone has experience with
testing for a comment, I'd be very appreciative. My code follows.
TIA,
Ken
Public Function fCellHasComment(lngStoreNumber As Long) As Boolean
On Error GoTo PROC_ERROR
Dim Cell As Range
With ThisWorkbook.Worksheets("Price Groups")
For Each Cell In Range("PriceGroupsStoreNumbers")
If Cell.Value = lngStoreNumber Then
If Cells(Cell.Row, Cell.Column).Comment.Text = "" Then
fCellHasComment = False
Else
fCellHasComment = True
End If
End If
Next Cell
End With
PROC_EXIT:
Exit Function
PROC_ERROR:
Call ShowError("modUtilities", "fCellHasComment", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
End Function
|