ReDim Statement

Allocates new memory for an array variable.


ReDim name ( dimensions ) [ , name ( dimensions ) ]…


An array variable.
One or more integer expressions, with a comma between each, all between parentheses.


You can use the statement ReDim to change the size of one or more dimensions of an array variable. If you make a large array and many elements are not used, ReDim can release memory with a smaller array. But, if your array is too small, ReDim can add elements.

You use ReDim only with arrays. You cannot use ReDim with scalars (variables that contain only one value) or structures.


Array bounds
Each dimension has a minimum index of zero and a maximum index that you supply. The supplied number is not the size of the dimension. The size of the dimension is the maximum index plus one.
The number of dimensions (rank) must be the same as those in the array declaration.
Data type
ReDim cannot change the data type of the elements of an array.
ReDim cannot change the number of dimensions (rank) of the array.


Replacement array
ReDim releases the memory used by the array, then makes a new array with the same rank. The new array replaces the released array in the array variable.
ReDim initializes the elements of the new array with the default value for the data type.



See also