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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

ParamRay

Well-known Member
Joined
Aug 6, 2014
Messages
1,195
.
.

It's because A1 already has a comment.

Clear the comment first and then try again...
 

fahadakbar

Board Regular
Joined
May 15, 2014
Messages
63
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>
 

ParamRay

Well-known Member
Joined
Aug 6, 2014
Messages
1,195
.
.

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,651
Messages
5,838,584
Members
430,557
Latest member
MK15

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
Top