copy cell into comment on another sheet

KeythStone

New Member
Joined
Mar 30, 2011
Messages
36
Hello to all,

I want to know if I can copy text in one cell on Sheet "test" and paste into a new comment on Sheet "report". I've seen some codes that go the other way around, extract the comment and move to another sheet. Kind of want to go the other way. Any ideas?

Stay smooth,

KeythStone
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Code:
    Dim cmt As Comment
    
    With Sheets("report").Range("C1")
        Set cmt = .Comment
        If cmt Is Nothing Then Set cmt = .AddComment
    End With
    cmt.Visible = False
    cmt.Text Text:=Sheets("test").Range("A1").Text

Excel Comments VBA
 
Upvote 0
Thanks AlphaFrog. This helps.

I need to use the above code as i cycle through two ranges. one range identifies where the comment boxes go, the other is from where the data text is stored to be put into the comment box. I have this so far:

Sub AddComments()
Dim commrange As String
Dim cmt As Comment

For Each c In Range("commrange")
If cmt Is Nothing Then Set cmt = c.AddComment
cmt.Visible = True
cmt.Text Text:=Sheets("test").Range("notes").Text
Next c
End Sub

I can see the inherent gap in logic as in the code, it doesn't know how to move through the range. And I do not know how to do so either. Thanks everyone.

Stay Smooth,
KeythStone
 
Upvote 0
Here's one way to do it...

Code:
Sub AddComments()
    
    Dim i      As Long
    Dim cmt    As Comment
    
    For i = 1 To Range("commrange").Count
        Set cmt = Range("commrange")(i).Comment
        If cmt Is Nothing Then Set cmt = Range("commrange")(i).AddComment
        cmt.Visible = True
        cmt.Text Text:=Sheets("test").Range("notes")(i).Text
    Next i
    
End Sub
 
Upvote 0
Thanks AlphaFrog for all your help. It works now. I hope to take this understanding and run with it. Here is the code I used:

Sub AddComments()

Dim i As Long
Dim cmt As Comment

For i = 1 To Range("commrange").Count
Set cmt = Range("commrange")(i).Comment
If cmt Is Nothing Then Set cmt = Range("commrange")(i).AddComment
cmt.Visible = False
cmt.Text Text:=Sheets("test").Range("notes")(i).Text
If Sheets("test").Range("notes")(i).Text = "" Then Exit For
Next i

End Sub

:)
 
Upvote 0
You're welcome. I'm glad you got it to work.

Two minor comments.

1.) shouldn't you test if then Notes text is equal to "" at the top of the loop?

Code:
Sub AddComments()

    Dim i      As Long
    Dim cmt    As Comment

    For i = 1 To Range("commrange").Count
        [COLOR="Red"]If Sheets("test").Range("notes")(i).Text = "" Then Exit For[/COLOR]
        Set cmt = Range("commrange")(i).Comment
        If cmt Is Nothing Then Set cmt = Range("commrange")(i).AddComment
        cmt.Visible = False
        cmt.Text Text:=Sheets("test").Range("notes")(i).Text
    Next i

End Sub

2.) Forum Tip: Pasting VBA code in the forum editor
For future reference, it would be best if you surround your VBA code with code tags e.g [CODE]your VBA code here[/CODE]
It makes reading your VBA code much easier.
When you're in the forum editor, highlight your pasted VBA code and then click on the icon with the pound or number sign #.
 
Upvote 0
This weekend i will sit down and read the rules to post on this site. I'd like to follow them, everyone here is so very helpful. Thanks,

Stay Smooth
KeythStone
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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