Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 从单元格中复制到下面的新注释中,然后继续执行此操作_Excel_Vba_Cell - Fatal编程技术网

Excel 从单元格中复制到下面的新注释中,然后继续执行此操作

Excel 从单元格中复制到下面的新注释中,然后继续执行此操作,excel,vba,cell,Excel,Vba,Cell,我找遍了所有的地方,只找到了一些似乎不协调的小片段 使用VBA,我试图将信息从一个单元格复制到它下面单元格的注释中;然后我想转到下一个单元格,重复10次 使表格更加紧凑,以便更容易查看重要信息,然后当您将鼠标悬停在单元格上时,您将看到注释(这将为您提供一条支持信息),这将非常有用 所以在第1行:我想把A1复制到A2的注释中,然后对B、C、D、E等做同样的操作,直到J 以下是我目前掌握的情况: Sub Comments() Dim c As Range, d As String Fo

我找遍了所有的地方,只找到了一些似乎不协调的小片段

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

使表格更加紧凑,以便更容易查看重要信息,然后当您将鼠标悬停在单元格上时,您将看到注释(这将为您提供一条支持信息),这将非常有用

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

以下是我目前掌握的情况:

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
子注释()
尺寸c作为范围,d作为字符串
对于选择中的每个c
如果是“c”,则d=d&c&Chr(10)
下一个
范围(“A2”).Comment.Delete
范围(“A2”)。添加注释d
端接头
范围需要是动态部分-从A1复制并粘贴到A2的注释中,然后重复,以便从B1复制到B2的注释中,等等

我希望这是有意义的…

试试这个:

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
子测试()
调光范围
'将表1换成合适的
对于工作表中的每个c(“表1”)。范围(“A1:J1”)
如果c.值为“”,则
对于c.Offset(1),Offset(1)表示获取下面的单元格
出错时继续下一步
.Comment.Delete“删除已存在的注释
错误转到0
.AddComment文本:=CStr(c.Value)'添加新注释
以
如果结束
下一个c
端接头
也许:

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 Comments()Dim c As Range,d As String For Selection中的每个c如果c“”,那么d=d&c&Chr(10)Next Range(“E42”).Comment.Delete Range(“E42”).AddComment d End Sub范围需要是当前选择下的动态部分,而不是E42。。。当我做对了,我可以移动到下一个单元格,直到J..Hmm-它不喜欢“.AddComment Text…”行。它返回一个应用程序定义的或对象定义的错误。你在我的代码中做了什么更改吗?它应该可以工作我没有改变任何东西,但是-没关系,我现在把代码改成了.Range(“A2:J2”),因为我认为第1行的偏移量不起作用。@simoco:试着在第一行放一个数字。Gary-谢谢,这很快就起作用了。我是这方面的新手,所以这是一个很大的帮助。谢谢。