Adding Comments with VBA, but only if there is not already a comment

Rebuild8

New Member
Joined
Mar 24, 2010
Messages
43
Hi
I would like to add comments to column A and use the text that is in column B. The problem is I get an error message if there is already a comment to a cell in column A. How can I rewrite my code so that it will not try to add a comment and just replace the text that was already there? (I get a run-time error and it highlights the AddComment line).

Sub ILuvComments()
lastrow = Range("B" & Rows.Count).End(xlUp).Row
For i = 1 To lastrow
Range("A" & i).AddComment
Range("A" & i).Comment.Text Text:=Range("B" & i).Value
Next i
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
One way:

Code:
Sub ILuvComments()
    Dim iRow As Long
 
    For iRow = 1 To Cells(Rows.Count, "B").End(xlUp).Row
        With Cells(iRow, "A")
            If .Comment Is Nothing Then
                .AddComment Text:=.Offset(, 1).Text
            End If
        End With
    Next iRow
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

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