VBA Multi-Dimensional Array in Excel.The Multi-Dimensional Arrays uses more than two indexes(Subscripts). We can have up-to 60 dimensions in an array.
Here is the Syntax of the Multi-Dimensional Array Function in Excel VBA.
Dim ArrayName(FirstIndexNumber,SecondIndexNumber,ThirdIndexNumber,...,_ NthIndexNumber) As DataType
where FirstIndexNumber,SecondIndexNumber,ThirdIndexNumber,…,_NthIndexNumber: These are mandatory argumnts. It represents the index or subscript value.
and DataType: It represnts the type of an array variables.
Let us see the example how to declare multidimensional array. In the below example shows an example for 2 dimensional array. we can create up to 60 dimensions. Mostly we create maximum of 3 dimensions.
Sub VBA_MultiDimensional_Array() 'Declare Multi Dimensional Array Dim aNEWS(3, 1) As String 'Assign Values to an array elements aNEWS(0, 0) = "1st" aNEWS(0, 1) = "North" aNEWS(1, 0) = "2nd" aNEWS(1, 1) = "East" aNEWS(2, 0) = "3rd" aNEWS(2, 1) = "West" aNEWS(3, 0) = "4th" aNEWS(3, 1) = "South" 'Access Array Elements MsgBox aNEWS(1, 1), vbInformation, "VBAF1" End Sub
Here is the screen shot of above macro output.
You can refer the following link for the step by step instructions.
Click on the following links of the useful resources. These helps to learn and gain more knowledge.