ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Verify if Comment exist in a cell (https://www.excelbanter.com/excel-discussion-misc-queries/45612-verify-if-comment-exist-cell.html)

Tom LeBold

Verify if Comment exist in a cell
 
How do you verify if a comment exist in each cell in a worksheet using VBA
code.
The following VBA code works for a verifying comments in a range: If
Range("A:A").Comment.Visible = True <

The following VBA code does not work for verifying if comments exist in a
cell:
If ActiveSheet.Cells(RowNbr, 1).Comment.Visible = True <

Received the following error: Object varible or With block variable not set.




Chip Pearson

Tom,

Dim C As Comment
On Error Resume Next
Set C = Range("A1").Comment
If Err.Number = 0 Then
' cell has comment, C
Else
' cell does not have comment
End If
On Error GoTo 0


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Tom LeBold" wrote in
message
...
How do you verify if a comment exist in each cell in a
worksheet using VBA
code.
The following VBA code works for a verifying comments in a
range: If
Range("A:A").Comment.Visible = True <

The following VBA code does not work for verifying if comments
exist in a
cell:
If ActiveSheet.Cells(RowNbr, 1).Comment.Visible = True <

Received the following error: Object varible or With block
variable not set.






Dave Peterson

Another way:

if activesheet.cells(rownbr,1).comment is nothing then
'no comment
else
'yep
end if



Tom LeBold wrote:

How do you verify if a comment exist in each cell in a worksheet using VBA
code.
The following VBA code works for a verifying comments in a range: If
Range("A:A").Comment.Visible = True <

The following VBA code does not work for verifying if comments exist in a
cell:
If ActiveSheet.Cells(RowNbr, 1).Comment.Visible = True <

Received the following error: Object varible or With block variable not set.


--

Dave Peterson


All times are GMT +1. The time now is 02:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com