VBA Multi-Dimensional Array in Excel

Multi - Dimensional Array

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.

VBA Multi Dimensional Array

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog

1 thought on “VBA Multi-Dimensional Array in Excel”

Leave a Comment