ReDim

Redim [Preserve] VariableName({NewDimensions})

Changes the dimensions of an array variable. The Preserve-keyword can be used to prevent erasing current values.

Dim mValues() As Double 'mValues is initially empty, thus UBound(mValues) is initially -1.

Public Function AddValue(pValue As Double)
   Redim Preserve mValues(UBound(mValues) + 1) 'Allocate one item extra, using Preserve
   mValues(UBound(mValues)) = pValue 'Put the pValue in the last added item
End Function

Public Function PrintValues()
   Dim lItem As Double
   
   For Each lItem In mValues
       SendDebug lItem
   Next
End Function

Public Function ResetValues()
   Redim mValues(-1) 'Clears all.
   'We do not use Erase, because Erase would only set the elements to 0, not remove them.
End Function

See also: