Declaring and Working with Dynamic Arrays : Dynamic Array « Date Functions « VBA / Excel / Access / Word






Declaring and Working with Dynamic Arrays

 
Sub DynamicArray()
    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"

    'Use a For...Each loop to loop through the
    'elements of the array
    For Each vntAny In astrNames
        Debug.Print vntAny
    Next vntAny
End Sub

 








Related examples in the same category

1.Dynamic Arrays
2.Use ReDim to create dynamic array
3.Using a Dynamic Array
4.There's a potential problem when you try to resize the 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.