The VBA._HiddenModule.Array
function has this signature:
Public Function Array(ParamArray ArgList() As Variant) As Variant
I'd guess it's basically just returning the ParamArray
pointer, effectively turning an inline sequence of elements into a simple one-dimensional Variant
array.
If that sequence of elements consists in elements that are themselves arrays, then you can have yourself a jagged array, or "array of arrays" - but not a 2D array:
Dim JaggedArray As Variant
JaggedArray = Array( _
Array(1, 2, 3, 4), _
Array(1, 2, 3, 4), _
Array(1, 2, 3, 4), _
Array(1, 2, 3, 4), _
Array(1, 2, 3, 4), _
Array(1, 2, 3, 4), _
)
You access its elements with successive subscripts:
Debug.Print JaggedArray(2)(3)
The biggest issue with that, is that you've turned data into code, and what's normally a good thing is to separate the data from the code.
If only there was a worksheet nearby to read the data from!
Dim twoDimensionalVariantArray As Variant
twoDimensionalVariantArray = Sheet1.Range("A1:D6").Value
Or better yet, use a named range:
twoDimensionalVariantArray = Sheet1.Range("ItemsSource").Value
Or an actual table:
twoDimensionalVariantArray = Sheet1.ListObjects("Table1").DataBodyRange.Value
All one-liners, no loop needed!
Given a range representing an area of two or more cells, Range.Value
returns a 2D Variant
array. Careful though, an array that came from a worksheet will always be 1-based so that indexes line up with row and column numbers (there no row or column 0 on a worksheet). Always use LBound(theArray, dimension)
and UBound(theArray, dimension)
to get the lower and upper boundaries of an array before you iterate it with a For...Next
loop.
You access its elements with 2D subscripts:
Debug.Print twoDimensionalVariantArray(2, 3)