arraysvbatype-2-dimension

Is there a way to create a 2-dimensional array in VBA using Array function>


I want to quickly create a 6X4 array of small integers. For a small 1-dimensional array, I like to use something like

Dim MyArr()
MyArr = Array(1,2,3,4,5,6)

Is there a similar way to create a 2-D array? I tried separating the rows with ; but

MyArr = Array (1, 2, 3; 4, 5, 6) is invalid.

I guess I'm being too lazy to set up the loops, but a one-line method would be compact and useful.


Solution

  • In Excel you can use Application.Evaluate (or the [] shortcut) and an array literal:

    MyArr = [{1,2;3,4}]