我还是VBA Excel编码的新手。如果有什么需要改进的地方,一定要告诉我。
在下面的例子中,我试图从generate类中获得偶数值的列表,并插入到excelvba表中。但是我该如何计算返回的列表的数量呢?
Private Function Generate()
Dim red(1 To 20) As String
For i = 1 To 20
red(i) = i * 2
Next i
Generate = red()
End Function
Sub Format()
Dim str() As String
str() = Generate
Range("A1").Select
With Selection
For i = 1 To str().Count 'what do I do with this? Obviously str().Count is not working.
.Offset(1, i).Value = str(i)
Next
End With
End Sub
谢谢。
我自己设法解决了问题,答案是:
Private Function Generate()
Dim red(1 To 20) As String
For i = 1 To 20
red(i) = i * 2
Next i
Generate = red()
End Function
Sub Format()
Dim str() As String
str() = Generate
Range("A1").Select
With Selection
For i = LBound(str) To UBound(str)
.Offset(i - 1, 0).Value = str(i)
Next
End With
End Sub