ReDim Statement

This statement increases or decreases an array size by changing the array's upper bounds.

ReDim [Preserve] variable_name (dim_1[, dim_2 …])

Prerequisites

The variable_name parameter must already be declared to be an array, with the same number of dimensions, in a Dim, Public, or Private statement.

Parameters

variable_name

The name of the array variable that is to have its size changed.

dim_1, dim_2, …

The new upper bounds for each dimension of the array. ReDim cannot change the number of dimensions, so the number of dimensions must match the original array declaration.

If the Preserve keyword is specified, all dimensions except the last (right-most) must remain the same.

Remarks

The previous contents of an array are lost when an ordinary ReDim statement is executed. If the Preserve keyword is specified, the previous contents of the array are preserved.

Examples

 Dim array(3,4) As Integer 
Dim array2() As String

ReDim array(4,6)
ReDim array2(10)
ReDim array2(2,3) ' Invalid, cannot change # of dimensions
ReDim Preserve array(3, 10)
ReDim Preserve array(4, 10) 'Invalid, can only change last dimension

See Also

Statements |Dim Statements