Excel VBA 从数组中添加评论
Excel VBA Add Comment from Array
我不明白为什么下面没有添加A1到A27的评论:(
Dim aComment As String
aComment = Split("ABC|DEF|GHI|JKL", "|")
For i = 1 To i = 27
For x = LBound(aComment) To UBound(aComment)
With Worksheets("report").Range(Cells(1, i)).AddComment
.Visible = False
.Text aComment(x)
End With
Next
Next
如果你能帮我一把,那就太棒了,知道我快到了,但不知道我错了什么:(
如果您想添加来自 A1:A4 的评论,此方法有效。
Dim aComment As Variant, i As Long
aComment = Split("ABC|DEF|GHI|JKL", "|")
For i = 1 To 4
Sheets("report").Range("A" & i).AddComment(aComment(i - 1)).Visible = False
'Sheets("report").Cells(1, i).).AddComment(aComment(i - 1)).Visible = False
Next
至于需要改进的地方:
- 您需要将
aComment
声明为 Variant
而不是 String
。
- 只需使用一个循环和一个线性语句。
- 并且您需要将
For Loop Syntax
从 For i = 1 To i = 27
修改为 For i = 1 To 27
我只在循环中使用 4
因为你只给了四个样本。你可以调整它以适应它。
我也很困惑。在你的问题中你想把它放在 A1:A27
但在评论 A1 到 D1.
无论如何我都提供代码。
我不明白为什么下面没有添加A1到A27的评论:(
Dim aComment As String
aComment = Split("ABC|DEF|GHI|JKL", "|")
For i = 1 To i = 27
For x = LBound(aComment) To UBound(aComment)
With Worksheets("report").Range(Cells(1, i)).AddComment
.Visible = False
.Text aComment(x)
End With
Next
Next
如果你能帮我一把,那就太棒了,知道我快到了,但不知道我错了什么:(
如果您想添加来自 A1:A4 的评论,此方法有效。
Dim aComment As Variant, i As Long
aComment = Split("ABC|DEF|GHI|JKL", "|")
For i = 1 To 4
Sheets("report").Range("A" & i).AddComment(aComment(i - 1)).Visible = False
'Sheets("report").Cells(1, i).).AddComment(aComment(i - 1)).Visible = False
Next
至于需要改进的地方:
- 您需要将
aComment
声明为Variant
而不是String
。 - 只需使用一个循环和一个线性语句。
- 并且您需要将
For Loop Syntax
从For i = 1 To i = 27
修改为For i = 1 To 27
我只在循环中使用 4
因为你只给了四个样本。你可以调整它以适应它。
我也很困惑。在你的问题中你想把它放在 A1:A27
但在评论 A1 到 D1.
无论如何我都提供代码。