There's a potential problem when you try to resize the array: : Dynamic Array « Date Functions « VBA / Excel / Access / Word






There's a potential problem when you try to resize the array:

 
Sub ResizeDynamic()
    Dim astrNames() As String
    Dim intCounter As Integer
    Dim vntAny As Variant

    'Resize the array to hold two elements
    ReDim astrNames(1)
    astrNames(0) = "A"
    astrNames(1) = "B"

    'Resize the array to hold four elements
    ReDim astrNames(3)

    'Populate the last two elements
    astrNames(2) = "C"
    astrNames(3) = "D"

    For Each vntAny In astrNames
        Debug.Print vntAny
    Next vntAny
End Sub

 








Related examples in the same category

1.Dynamic Arrays
2.Declaring and Working with Dynamic Arrays
3.Use ReDim to create dynamic array
4.Using a Dynamic Array
5.A destroying the old values by using the Preserve keyword
6.Use the Preserve keyword to keep the values
7.Transpose() sub procedure is using a dynamic array that is re-dimensioned with two dimensions.