Excel VBA - How to set a comment on a cell with VBA?

behedwin

Active Member
Joined
Dec 10, 2014
Messages
399
How can i populate a cell with a comment using VBA code?

And then how to make the text in the comment hold a cell´s value like A1
And how to make a new line in a cell comment?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Code:
Range("B1").NoteText "Hi. I'm a comment"
Range("B2").NoteText "When this code was exicuted, the value in A1 was " & Range("A1").Text

Range("B3").NoteText "Comments do not contain dynamic contents" & vbCr & "Auto updating the comment in B2 would require VBA"

Or you could use the MacroRecorder to find a different syntax for adding a comment.
 
Upvote 0
Code:
Range("B1").NoteText "Hi. I'm a comment"
Range("B2").NoteText "When this code was exicuted, the value in A1 was " & Range("A1").Text

Range("B3").NoteText "Comments do not contain dynamic contents" & vbCr & "Auto updating the comment in B2 would require VBA"

Or you could use the MacroRecorder to find a different syntax for adding a comment.

Ok i got it to work now.
But as you said the content is not dynamic.
I first loaded with your text... then changed to my text.... and now still yours text are still in the comment.... How to get it to update the data?

Adding this line gives me an empty box of a comment
Code:
Range("G4").NoteText Range("G4").Text & "random text: " & Range("h4").Text & "random text " & vbCr & "random text" & Range("i4").Text & " random text" & vbCr & Range("g4").Text & " random text " & Range("j4").Text & " random text " & vbCr & "kljölkj lökjölkj " & Range("k4").Text & " jlaösjfdslkfjsdlök " & vbCr & "text text tdslfaj " & Range("l4").Text
 
Last edited:
Upvote 0
I solved this by giving up the idea of using "comment".
Created a label instead that i hide/unhide on click on a cell instead.
It was a bit more "code"... but it works as i want still.

Found quite allot of different approaches to handle comment/notes in excel.
I never got any of them to work well... even tho i think made some kind of mistakes on the road :)
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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