vba redim preserve code example
Example 1: vba redim preserve
Dim MyArray() As String
ReDim MyArray(1)
MyArray(0) = "zero"
MyArray(1) = "one"
ReDim Preserve MyArray(2)
MyArray(2) = "two"
MsgBox MyArray(0) & " " & MyArray(1) & " " & MyArray(2)
Example 2: vba redim
' Used at the procedure level to reallocate storage space for dynamic array variables.
' Example
Dim arr() as Long
ReDim ar() 'creates new array "ar" - "ReDim ar()" acts like "Dim ar()"