jonathan7272
New Member
- Joined
- Mar 12, 2011
- Messages
- 20
Hi everyone,
I'm having such a nightmare with this. Could someone please explain what I'm doing wrong! I am wanting to redim an array, while preserving the existing data. I have simplified the kind of thing I'm trying to do in the code below. If I run this I get the error message "Run-time error '9': Subscript out of range".
Sub test()
Dim anArray() As String
ReDim anArray(10, 2)
For x = 0 To UBound(anArray)
anArray(x, 1) = x
Next x
ReDim Preserve anArray(20, 2)
For x = 0 To UBound(anArray)
Debug.Print anArray(x, 1)
Next x
End Sub
I'm having such a nightmare with this. Could someone please explain what I'm doing wrong! I am wanting to redim an array, while preserving the existing data. I have simplified the kind of thing I'm trying to do in the code below. If I run this I get the error message "Run-time error '9': Subscript out of range".
Sub test()
Dim anArray() As String
ReDim anArray(10, 2)
For x = 0 To UBound(anArray)
anArray(x, 1) = x
Next x
ReDim Preserve anArray(20, 2)
For x = 0 To UBound(anArray)
Debug.Print anArray(x, 1)
Next x
End Sub