Set a cell comment using VBA?

AChimpNamedCornelius

Board Regular
Joined
Aug 22, 2002
Messages
91
I am stumped by this, and am not sure if this even can be done. The documentation is contradictory.

I want to set the comment text of a cell using VBA.

I tried:

Sheet1.Range("D6").Comment.Text = "Hello"

with and without Set in front of it. I get the error "Assignment to constant not permitted" (compile time error)


And this:

Sheet1.Range("D6").Comment = "Hello"

yields a run time error of "Object doesn't support this property or method."

Assigning the cell to a variable dimmed as a Range doesn't get around it either.


Now, from the documentation for .Text:

Text Property


Returns or sets the text for the specified object. Read-only String for the Range object, read/write String for all other objects.

But, also from help:


Comment Property Example

This example sets the comment for scenario one on Sheet1.

Worksheets("Sheet1").Scenarios(1).Comment = _
"Worst case July 1993 sales"


So what am I doing wrong? I am not familiar with the .Scenarios member object, but why would one need to use it to adjust the comment of a cell or range of cells? If that is the only way, then how do I use .Scenarios to set the comment of, say, cell "D6"?

Thanks for any help anyone can give me.
 
I think the issue was that comments appear to be read only (MS programmer woke up on the wrong side of the bed that day), so clearcomment deleted it so it could be recreated. The other example did not do this.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi Jay,
I wanted to include a condition here in cell D6, that is to insert a comment when the value in D6 is "No", and the comment should be auto-inserted (with a specific which I can define or refer a cell) without I having to run a macro
 
Upvote 0
I'll leave the declarations out but I found this little nugget and it works for me in Excel 2013 on Windows 10.

VBA Code:
For Each Comment In ActiveSheet.Comments
   With Comment
      curComment = .Text
      curComment = "***" & curComment
      .Text Text:=curComment
   End with
Next
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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