VBA Three Dimensional Array in Excel. The dimensional Array has three dimensions and uses three indexes(Subscripts). The three subscripts(indexes) are separated with comma symbol. For example one index represents the rows, second one represents the columns and third one represents the charts. We refer Excel worksheet or cube for 3 Dimensional arrays.
Here is the Syntax of the 3Dimensional Array Function in Excel VBA.
Dim ArrayName(FirstIndexNumber,SecondIndexNumber,ThirdIndexNumber) As DataType
where FirstIndexNumber, SecondIndexNumber and ThirdIndexNumber: 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 VBA macro code on static 3Dimensional Array in Excel.
'VBA Dynamic 3Dimensional Array Sub VBA_Dynamic_Three_Dimensional_Array() 'Declare Variable Dim aType() Dim iRow As Integer, iCol As Integer, iSht As Integer 'Initialize an array size ReDim aType(2, 2, 2) 'Loop through rows For iRow = 0 To UBound(aType, 1) 'Loop through columns For iCol = 0 To UBound(aType, 2) 'Loop through sheets For iSht = 1 To UBound(aType, 3) aType(iRow, iCol, iSht) = ThisWorkbook.Sheets("Sheet" & iSht).Cells(iRow + 1, iCol + 1) 'Check output in immediate window Debug.Print aType(iRow, iCol, iSht) Next Next Next End Sub
You can view output in the immediate window.
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.