Inserting Comments in Excel through VBA

fahadakbar

Board Regular
Joined
May 15, 2014
Messages
63
[TABLE="width: 512"]
<tbody>[TR]
[TD="colspan: 3"]I have a question[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]I want a comment at A1 which will have text that is in cell B1 , B2 and B3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]e.g B1, B2, & B3 has A , B & C in there [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]I want the macro to insert a comment in A1 with the text A,B,C[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]any way to do that ?[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody><colgroup><col span="8"></colgroup>[/TABLE]
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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,224,427
Messages
6,178,586
Members
452,860
Latest member
jroberts02

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