multi dim array vba code example

Example 1: vba multiple dim

Dim a, b As Integer
' is equivalent to
Dim a As Variant, b As Integer

' Declare a and b as Integer:
Dim a As Integer
Dim b As Integer
' Or:
Dim a As Integer, b As Integer

Example 2: vba multidimensional array

Sub CreatingArrays()
	
    'Declarating
    Dim arrVar(0 to 3, 0 to 5) As Variant 'Creating an array of 4x6 dimensions
    Dim strArr(3,5) As String 			  'Creating an string array of 4x6 dimensions
    
    'Contro Variables
    Dim i As Integer
    Dim j As Integer
    Dim intCount as Integer
    
    'Fulling up Arrays
    For i = LBound(arrVar) To UBound(arrVar)
    	For j = LBound(arrVar, 2) To UBound(arrVar, 2)
        	arrVar(i, j) = intCount
            arrStr(i, j) = "X, Y: " & i & ", " & j
            intCount = intCount + 1
        Next j
    Next i
    
End Sub

Tags:

Vb Example