I am trying to find a practical way of directly allocating values to a multidimensional array in VBA without iterating. I Googled a solution which kind of works, but it fails when I try to use it in combination with variables..
This works:
Sub SomeSub()
Dim vArray As Variant
Dim iCounter As Integer
vArray = [{"Zip", "22150";"City", "Springfield"; "State", "VA"}]
For iCounter = LBound(vArray, 1) To UBound(vArray, 1)
Debug.Print vArray(iCounter, 1), vArray(iCounter, 2)
Next iCounter
End Sub
This, however, does not, and raises a "Type mismatch" error instead. The difference is that I try (and wish) to use variables instead of constant values:
Sub SomeSub()
Dim vArray As Variant
Dim iZip As Integer
Dim sCity As String
Dim sState As String
iZip = 22150
sCity = "Springfield"
sState = "VA"
Dim iCounter As Integer
vArray = [{"Zip", iZip;"City", sCity; "State", sState}]
For iCounter = LBound(vArray, 1) To UBound(vArray, 1)
Debug.Print vArray(iCounter, 1), vArray(iCounter, 2)
Next iCounter
End Sub
I find little or no information on this method for allocating arrays, so I'm hoping that someone has some insight to offer.
Thanks!