VBA Multi-Dimensional Array in Excel
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.
Syntax of the Multi-Dimensional Array Function
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.
Example for VBA N-Dimensional Array in Excel
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.

Instructions to use Macro
Here are the instructions to use above macro in Visual basic editor.
- Open Visual Basic Editor(VBE) by clicking Alt +F11
- Go to code window by clicking F7
- Copy above specified macro or procedure
- Paste above copied code in code window
- Run macro by clicking F5 or Run command
- You can see output on the screen
- Find above specified output screenshot.
Other Related VBA Arrays articles
You may also like the related VBA Array articles.