Team,
After this last upgrade Microsoft pushed this past weekend, many of my workbooks stopped working when I go from Redim vArray(0 to 0) to Redim Preserve vArray(1 to 1) - Apparently 1 is skipped.
Simple Code 1 - Not working:
------
Simple Code 2 - Ugly Workaround that works
Can anybody tell what happened, I can spend a ton of time implementing the workaround, but what did Microsoft do? Why??
Thanks!!
After this last upgrade Microsoft pushed this past weekend, many of my workbooks stopped working when I go from Redim vArray(0 to 0) to Redim Preserve vArray(1 to 1) - Apparently 1 is skipped.
Simple Code 1 - Not working:
Code:
Private Sub ArrayTest1()
Dim vArray As Variant
ReDim vArray(0 To 0)
ReDim Preserve vArray(1 To 1)
MsgBox (UBound(vArray)) ' Returns 0?????
ReDim Preserve vArray(1 To 2)
MsgBox (UBound(vArray)) ' Returns 2
ReDim Preserve vArray(1 To 3)
MsgBox (UBound(vArray)) ' Returns 3
End Sub
Simple Code 2 - Ugly Workaround that works
Code:
Option Explicit
Private Sub ArrayTest2()
Dim vArray As Variant
ReDim vArray(-1 To 0) 'Crazy but it works!!!!
ReDim Preserve vArray(1 To 1)
MsgBox (UBound(vArray)) ' Returns 1 - Check!
ReDim Preserve vArray(1 To 2)
MsgBox (UBound(vArray)) ' Returns 2 - Check!
ReDim Preserve vArray(1 To 3)
MsgBox (UBound(vArray)) ' Returns 3 - Check!
End Sub
Thanks!!
Last edited by a moderator: