添加到Excel VBA中的数组函数

我正在尝试在for循环中将一个数组添加到Double数组的数组中。 这里是我有的代码:

Sub Test3() Dim a() As Double, i As Integer ReDim a(1 To 10, 1 To 3) Dim d For i = 1 To 3 d = Array(a) Next i End Sub 

在这个testing中,我只是想把“a”的3个副本join到“d”中。 我有d = Array(a)哪个当然不起作用,但是我不知道用什么行来replace它

编辑的代码清晰

新代码尝试:

 Sub Test3() Dim a() As Double, i As Integer ReDim a(1 To 10, 1 To 3) a(1, 2) = 3.5 Dim d() As Variant For i = 1 To 3 ReDim Preserve d(1 To i) d(i) = Array(a) Next i Dim x() As Double x = d(1) ' Error, Type Mismatch MsgBox (x(1, 2)) End Sub 

我得到了x = d(1)上types不匹配的错误,

你想要什么叫“锯齿arrays”,或数组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