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>
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

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
 

Watch MrExcel Video

Forum statistics

Threads
1,109,436
Messages
5,528,749
Members
409,834
Latest member
vexceled

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top