Inserting Comments in Excel through VBA

fahadakbar

Board Regular
Joined
May 15, 2014
Messages
63
I have a question
I want a comment at A1 which will have text that is in cell B1 , B2 and B3
e.g B1, B2, & B3 has A , B & C in there
I want the macro to insert a comment in A1 with the text A,B,C
any way to do that ?

<tbody>
</tbody><colgroup><col span="8"></colgroup>
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
For the first request, something like this should work.

Code:
Sub AddComment()
With Range("A1")
    .AddComment (Range("B1").Value & "," & Range("B2").Value & "," & Range("B3").Value)
End With
End Sub
 
Upvote 0
yes it works... but these are not the only cells having text... B5 or B7 can also have text, and I want them to be included as well ... just like an ongoing thing
 
Upvote 0
For including all text in column B, you can use this.

Code:
Sub AddComment()
Dim LastRow As Long
Dim c As Range
Dim strText
LastRow = Cells(Rows.count, 1).End(xlUp).row

For Each c In Range("B2", "B" & LastRow)
    strText = strText & c.Text & vbCrLf
Next c
With Range("A1").AddComment(strText)
    .Shape.TextFrame.AutoSize = True
End With
    Range("A1").Select

End Sub

The problem is, if you have a blank cell, it will be blank on the comment, but it might not be a big issue.
 
Upvote 0

Forum statistics

Threads
1,214,544
Messages
6,120,126
Members
448,947
Latest member
test111

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