View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban[_2_] Alan Beban[_2_] is offline
external usenet poster
 
Posts: 783
Default array dimensioning

Rick Rothstein (MVP - VB) wrote:
Then you missed the part where Chip wrote about the Preserve keyword.

You can ReDim the array as often as you want. ReDim will cause the
existing
contents of the array to be lost unless you use the Preserve modifier.

ReDim Preserve Arr(0 To 11)



Rick


A bit more needs to be said.

If Arr is a true variant() type array [e.g.,
Dim Arr()
ReDim Arr(1 to 10, 1 to 2)]
then with the Preserve keyword you can change only the upper bound of
the last dimension
[e.g.,
Dim Arr()
Redim Arr(1 to 10, 1 to 2)
ReDim Preserve Arr(1 to 10, 1 to 4)]
In this case, if you try to change either bound of the 1st dimension, or
the lower bound of the 2nd dimension, you will get a Subscript out of
range error.

If, however, Arr is a an array contained within a Variant type variable
[e.g.,
Dim Arr
Redim Arr(1 to 10, 1 to 2)]
then with the Preserve keyword you can change either or both bounds of
the last dimension [e.g.,
Dim Arr
Redim Arr(1 to 10, 1 to 2)
ReDim Preserve Arr(1 to 10, 0 to 3)]

If the functions in the freely downloadable file at
http:/home.pacbell.net/beban are available to your workbook, then you
can use the ResizeArray function to preserve the values of the array
that is passed to it and change the lower and/or upper bounds of any or
all of the dimensions of a one-, two- three- or four-dimensional
array, or increase (up to 4) or decrease the number of the array's
dimensions (whether or not the array is contained within a Variant type
variable).

Alan Beban