你如何计算VBA Excel的字符串列表?

时间:2014-10-01 05:54:53

标签: vb.net excel vba

我还是VBA Excel编码的新手。请告诉我是否有任何需要改进的地方。

在下面的示例中,我试图从generate类中获取偶数值列表并插入excel vba表。但是我如何计算返回的列表数量?

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

谢谢。

1 个答案:

答案 0 :(得分:0)

管理我自己解决,这就是答案:

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