我有3个阵列,每个阵列包含3个范围。我想将这些数组存储在一个数组中。我尝试执行以下操作:
Function test()
Dim a() As Range
Dim b() As Range
Dim c() As Range
a = getA(dataWorkbook) 'a(1)=Range(...), a(2)=Range(...), a(3)=Range(...)
b = getB(dataWorkbook)
c = getC(dataWorkbook)
Dim allArrays(1 To 3) As Range
' allArrays(1) = a
' allArrays(2) = b
' allArrays(3) = c
test="HELLO"
End Function
但是,如果我使用allArrays
赋值取消注释行,则该函数返回!VALUE而不是" HELLO"。我做错了什么?
答案 0 :(得分:1)
创建锯齿状阵列的最佳方法是使用Variant
:
Dim allArrays As Variant
ReDim allArrays(1 To 3)
'rest of code will work as intended
您可以简化代码,只需使用Array
功能:
Dim allArrays As Variant
allArrays = Array(a, b, c)
虽然在这种情况下allArrays
将基于0而不是基于1。