Copy cell contents into cell comment

User avatar
ErikJan
BronzeLounger
Posts: 1250
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Copy cell contents into cell comment

Post by ErikJan »

I have a cell with a lot of text. I want to copy that text and add it to a cell-comment. How do I start?

User avatar
StuartR
Administrator
Posts: 12611
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Copy cell contents into cell comment

Post by StuartR »

To add a comment to a cell you use syntax like

Code: Select all

With Worksheets(1).Range("A1").AddComment 
    .Visible=True 
    .Text= "Whatever"
End With
StuartR


User avatar
ErikJan
BronzeLounger
Posts: 1250
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Copy cell contents into cell comment

Post by ErikJan »

Thanks, that is probably the part I could figure out. Question is, how do I get the cell text in a variable (it's > 1000 chars!) and then that variable into the comment?

I tried this, the first part works; but get an error when I assign the .TEXT:

Code: Select all

t = Range("F3").Text
With ActiveSheet.Range("E3").AddComment
    .Visible = True
    .Text = t
End With

User avatar
StuartR
Administrator
Posts: 12611
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Copy cell contents into cell comment

Post by StuartR »

Sorry, that was my error. The correct syntax for that line is
.Text t
not
.Text = t

Try replacing your code with

Code: Select all

Dim rng As Range
    Set rng = ActiveSheet.Range("F3")
    With rng.AddComment
        .Visible = True
        .Text rng.Value
    End With
    Set rng = Nothing
StuartR


User avatar
ErikJan
BronzeLounger
Posts: 1250
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Copy cell contents into cell comment

Post by ErikJan »

OK, works. Thank you