Peter T wrote:
Tushar,
Hope it's not picky to point out your example would fail in XL97
ReDim arr(1 To 5)
arr = Range("A1:A3")
'compile error, can't assign to array (xl97)
but this is OK in xl97
Dim arr
arr = Range("A1:A3")
recently http://tinyurl.com/4ydfd
Alan,
Another highly contrived scenario when it is necessary to declare before
Redim
Sub test()
Dim x, i
Dim arr() As Long 'fails if commented
x = 20
For i = 1 To x
If i = 5 Then Exit For
ReDim Preserve arr(1 To i)
arr(i) = i
Next
MsgBox UBound(arr)
End Sub
Regards,
Peter
Hi Peter,
This doesn't really seem to be a Dim...ReDim problem as you can see by
commenting out the ReDim statement instead of the Dim statement. That's
also suggested by your commenting out the Dim statement, since the error
in that case is not "Invalid ReDim" but "Variable not defined".
Regards,
Alan Beban