从一个单元格复制到下面的新评论,然后再次进行

我已经看了所有,只发现一些似乎不能一起工作的片段。

使用VBA,我试图将单元格中的信息复制到它下面的单元格的注释中; 然后我想要移动到下一个单元格并重复10次。

让桌子变得更加紧凑以便查看重要信息会更加容易,然后当您将鼠标hover在单元格上时,您会看到评论(提供了一条支持信息),这将非常有用。

所以在第1行:我想复制A1到A2的注释中,然后对B,C,D,E等做同样的操作。

以下是我到目前为止:

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 

范围需要是dynamic的部分 – 从A1复制,并粘贴到A2的评论,然后重复,以便从B1复制到B2的评论等。

我希望这是有道理的…

也许:

 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 

试试这个:

 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