Fill a multidimensional array

I was wondering how to populate a multidimensional array in Excel VBA. The 1st array can be filled as follows:

Dim myarray as variant myarray = Array("sheep", "goat", "chicken") 

How can I fill each row separately for a multidimensional array?

+6
source share
1 answer

You can do it:

 Dim a a = [{1,2;3,4;5,6}] 

Limitations:

  • This only works with arrays of the Variant type, because [x] is short for Evaluate("x") , which means that x interpreted through Excel, and Excel returns only options. Thus, declaring a Dim a As Variant or an array of Dim a() As Variant works fine. But not any other type of array, for example. Dim a() As String does not work.

  • This only works for one specific type of multidimensional array, namely two-dimensional arrays. Not three, four, etc.

+12
source

Source: https://habr.com/ru/post/977892/


All Articles