Reading Comments

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I'd like to read any comment in my worksheet. I'm going through row by row (my variable i) with code
VBA Code:
For Pos = 1 To 10
      CR = colLetter(Pos)
       If .Range(CR & i).Comment.Text > "" Then
       Stop
       End If
Next
Function colLetter(intNumber) As String
    If Val(intNumber) = 0 Then
        colLetter = ""
    Else
        colLetter = Left(Cells(1, Val(intNumber)).Address(0, 0), 2 + (Val(intNumber) <= 26))
    End If
End Function
If there's no comment I have to trap this error
Run-time error '91':
Object variable or With block variable not set


Is this an OK approach, or perhaps a better method exists ?
Thanks.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Something like this :
VBA Code:
Dim cmnt As Comment
For Each cmnt In Sheet1.Comments
    Debug.Print cmnt.Text
Next cmnt

Change Sheet1 to suit.
 
Upvote 0
Thanks. That seems a really good approach, but is there any way to find the cmnt.text.address ?
 
Upvote 0
This should read the text of all comments in Sheet1 along with their cells addresses :
VBA Code:
Dim cmnt As Comment
For Each cmnt In Sheet1.Comments
    Debug.Print "Cell Address : " & cmnt.Parent.Address
    Debug.Print "Comment Text : " & cmnt.Text & vbLf & "___________________" & vbLf
Next cmnt
 
Upvote 0
I'm getting error Assignment to constant not permitted if try to assign or edit cmnt.text.
You may have a good way to get around that, mine is a bit overkill. But I do want to keep the same formatting. shape that exists
 
Upvote 0
I'm getting error Assignment to constant not permitted if try to assign or edit cmnt.text.
You may have a good way to get around that, mine is a bit overkill. But I do want to keep the same formatting. shape that exists
Can you post the code.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top