Question

I've looked all over and only find little snippets that don't seem to work together.

Using VBA, I'm trying to copy the information from a cell into a comment on the cell below it; I then want to move on to the next cell and repeat 10 times.

It'll be so useful to make a table much more compact so that it's easier to view the important information, and then when you hover over a cell you see the comment (which gives you a piece of support information).

So in row 1: I want to copy A1 into the comments of A2 and then do the same for B,C,D,E etc up to J.

Here's what I have so far:

Sub Comments()
   Dim c As Range, d As String

   For Each c In Selection
      If c <> "" Then d = d & c & Chr(10)
   Next

   Range("A2").Comment.Delete
   Range("A2").AddComment d
End Sub

The Range needs to be the dynamic part - copying from A1 and pasting into the comment of A2 and then repeating so that it copies from B1 into comments of B2 etc..

I hope that makes sense...

Was it helpful?

Solution

Perhaps:

Sub CommentAdder()
    Dim r As Range, Big As Range
    Set Big = Range("A1:J1")
    Big.Offset(1, 0).ClearComments
    For Each r In Big
        v = r.Text
        With r.Offset(1, 0)
            .AddComment
            .Comment.Visible = False
            .Comment.Text Text:=v
        End With
    Next r
End Sub

OTHER TIPS

Try this one:

Sub test()
    Dim c As Range
    'change Sheet1 to suit
    For Each c In Worksheets("Sheet1").Range("A1:J1")
        If c.Value <> "" Then
            With c.Offset(1) ' Offset(1) means get cell below
                On Error Resume Next
                .Comment.Delete ' delete comment if it's already exist
                On Error GoTo 0
                .AddComment Text:=CStr(c.Value) 'add new comment
            End With
        End If
    Next c
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top