WhyDidntItWork
asked on
Subscript out of range error
Hi,
I'm trying to redim a dynamic multi-dimensional array. However, no matter how I frame the redim statement, it doesn't work.
I'm trying to redim a dynamic multi-dimensional array. However, no matter how I frame the redim statement, it doesn't work.
Sub test()
Dim yabba() As Variant
ReDim yabba(10, 1)
yabba(0, 0) = "a"
yabba(0, 1) = 1
yabba(1, 0) = "b"
yabba(1, 1) = 2
yabba(2, 0) = "c"
yabba(2, 1) = 3
ReDim Preserve yabba(3)
MsgBox (UBound(yabba))
End Sub
Deleted.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could do this:
My profile contains links to some articles that may interest you.
Marty - MVP 2009 to 2012
Option Explicit
Private Type MyType
Var1 As String
Var2 As Integer
End Type
Private Sub Form_Load()
Dim yabba() As MyType
ReDim yabba(10)
yabba(0).Var1 = "a"
yabba(0).Var2 = 1
yabba(1).Var1 = "b"
yabba(1).Var2 = 2
yabba(2).Var1 = "c"
yabba(2).Var2 = 3
ReDim Preserve yabba(3)
MsgBox (UBound(yabba))
End Sub
My profile contains links to some articles that may interest you.
Marty - MVP 2009 to 2012