且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

添加到Excel中VBA数组功能

更新时间:2023-12-06 11:37:22

您想要什么叫做阵列的铁血阵列或阵列

You want what's called a "Jagged Array", or Array of Arrays

试试这个

Sub Demo()
    Dim a() As Double, b() As Double, c() As Double, i As Integer

    ReDim a(1 To 10, 1 To 3)
    ReDim b(1 To 2, 1 To 4)
    ReDim c(1 To 5, 1 To 11)

    a(1, 2) = 3.5
    b(1, 2) = 2.5

    Dim d As Variant
    ReDim d(1 To 6)

    ' Add 3 copies of a to d
    For i = 1 To 3
     d(i) = a
    Next i

    ' add other arrays to d
    d(4) = b
    d(5) = c

    ' Access elements of d
    Dim x() As Double
    x = d(1)

    MsgBox x(1, 2)
    MsgBox d(1)(1, 2)
    MsgBox d(4)(1, 2)
End Sub