What is the syntax to ReDim an array?

Note: ReDims only work for dynamic declarations, not static ones.

Redim <arrayname>(<index>)
Dim badArray(3) As Variant 'static declaration
Dim myArray1() As Variant 'dynamic declaration

ReDim myArray1(3)
myArray1(0) = "z"
myArray1(1) = "zz"
myArray1(2) = "zzz"

ReDim Preserve myArray1(4) 'still keeps previous values in the array
myArray1(3) = "zzzz"
‘array now contains “z,zz,zzz,zzzz”

ReDim myArray1(3) 'erases all previous values in the array
‘array is now empty

Published by