ReDim statement
Declare dynamic array variables at the procedure level and allocate or reallocate storage space.
ReDim [Preserve] varname(subscripts) [, varname(subscripts)] . . .
Parameters
Preserve
Preserves data when changing the size of the last dimension of an existing array.
VarName
Variable names, followed by standard variable naming conventions.
subscripts
The number of dimensions of an array variable that can declare up to 60 dimensional arrays. The syntax format for the subscripts parameter is as follows:
Upper [, Upper] ...
The lower bound of an array is always zero.
Description
ReDim statements are typically used to specify or modify the size of a dynamic array that has been formally declared with a Private, public, or Dim statement with empty parentheses (no dimension subscript). You can use the ReDim statement repeatedly to change the number of array dimensions and elements.
If you use the Preserve keyword, you can only resize the last dimension of the array, and you cannot change the dimension of the array. For example, if the array has only one dimension, you can modify the size of the array, because the dimension is the last and only one-dimensional one. However, if the array has two or more dimensions, it can only change the size of the last dimension and preserve the contents of the array.
This example shows how to increase the number of aborted dimensions of a dynamic array without erasing the data that exists in the array.
ReDim X(10, 10, 10). . .ReDim Preserve X(10, 10, 15)
Be careful if you decrease the size of the array, the data in the excluded element is lost.
When a variable is initialized, the numeric variable is initialized to 0, and the string variable is initialized to a zero-length string (""). Before you use a variable that references an object, you must use the Set statement to assign an existing object to the variable. The declared object variable has a specific value of nothing before the object assignment.