How to Copy Cell Comments to Another Cell via VBA

jay333

New Member
Joined
Nov 5, 2010
Messages
17
I am seeking a way to copy a cells contents to another cell (including comments) to another cell. I am trying to format it something like:

sheet1.cells(2,3) = sheet2.cells(5,6).

the above does not move comments that exist in the sheet2 cell to the sheet 1 cell.

Was trying something like sheet1.cells(2,3) = sheet2.cells(5.6).comments.text. However, this does not work.

Any suggestions?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
you could use pastespecial to dump the comments...
copy the contents then:

Code:
    Selection.PasteSpecial Paste:=xlPasteComments, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
 
Upvote 0
Another method...

Code:
[color=darkblue]With[/color] Sheet1.Cells(2, 3)
    .ClearComments [color=green]'Clear comment if already exists[/color]
    .AddComment Sheet2.Cells(5, 6).Comment.Text
[color=darkblue]End[/color] [color=darkblue]With[/color]
 
Last edited:
Upvote 0
Another method...

Code:
[COLOR=darkblue]With[/COLOR] Sheet1.Cells(2, 3)
    .ClearComments [COLOR=green]'Clear comment if already exists[/COLOR]
    .AddComment Sheet2.Cells(5, 6).Comment.Text
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]


This does work (sort of). I do get an error when the vba code runs although in the end it does put the comment into the cell. I'm thinking the error has something to do with the target sheet being protected or something?
 
Upvote 0
The lines in red allow the macro to make changes to comments on the protected worksheetsheet. Change the password to suit.

Code:
With Sheet1.Cells(2, 3)
    [COLOR="Red"].Parent.Protect Password:="[COLOR="Blue"]Secret[/COLOR]", DrawingObjects:=False[/COLOR]
    .ClearComments 'Clear comment if already exists
    .AddComment Sheet2.Cells(5, 6).Comment.Text
    [COLOR="Red"].Parent.Protect Password:="[COLOR="Blue"]Secret[/COLOR]"[/COLOR]
End With
 
Last edited:
Upvote 0
The lines in red allow the macro to make changes to comments on the protected worksheetsheet. Change the password to suit.

Code:
With Sheet1.Cells(2, 3)
    [COLOR=red].Parent.Protect Password:="[COLOR=blue]Secret[/COLOR]", DrawingObjects:=False[/COLOR]
    .ClearComments 'Clear comment if already exists
    .AddComment Sheet2.Cells(5, 6).Comment.Text
    [COLOR=red].Parent.Protect Password:="[COLOR=blue]Secret[/COLOR]"[/COLOR]
End With

Unfortunately, I am still getting an error. It is "Run-time erros '91', Object variable or With block variable not set". And, the '.AddComment' line is highlighted.

Any further thoughts?
 
Upvote 0
AlphaFrog

And how to implement such:
1. I have 'comment' in the cell. In this cell there is some 'text'.
2. How to copy only 'comment' to another cell. In the other cell with only 'text' (but some records in another cell should not be overwritten)!
That is, I need Copy-Paste.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
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