inserting Comments through VBA

fahadakbar

Board Regular
Joined
May 15, 2014
Messages
63
Hello friends
I am trying to put some comments in a sheet through VBA
I know that how to put in a comment. I can use
Range("A1").AddComment("vvv").Visible =False
and this will work perfectly
However, when I use another reference style "Cells" - it doesn't work e.g
Cells(1,1).AddComment("vvv").Visible = False
this will give me a object definition error--
Does anyone know why it happens ? and hot to fix it ?

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

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
.
.

It's because A1 already has a comment.

Clear the comment first and then try again...
 
Upvote 0
I have another question
I want a comment at A1 which will have text that is in cells 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>
 
Upvote 0
.
.

Code:
Sub Add_Comment()
    
    Dim ComTxt As String
    
    ComTxt = _
        Range("B1") & " " & _
        Range("B2") & " " & _
        Range("B3")
    
    With Range("A1")
        
        On Error Resume Next
            .ClearComments
        On Error GoTo 0
        
        .AddComment
        .Comment.Text Text:=ComTxt
    
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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