Link to home
Start Free TrialLog in
Avatar of WhyDidntItWork
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.

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

Open in new window

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Deleted.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could do this:

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

Open in new window


My profile contains links to some articles that may interest you.
Marty - MVP 2009 to 2012