Items are removed from a
Collection by calling its
|index||The item to remove from the |
Collectionwill change the numeric indexes of all the items after it in the
Forloops that use numeric indexes and remove items should run backwards (
Step -1) to prevent subscript exceptions and skipped items.
Collectionfrom inside of a
For Eachloop as it can give unpredictable results.
Public Sub Example() Dim foo As New Collection With foo .Add "One" .Add "Two", "Second" .Add "Three" .Add "Four" End With foo.Remove 1 'Removes the first item. foo.Remove "Second" 'Removes the item with key "Second". foo.Remove foo.Count 'Removes the last item. Dim member As Variant For Each member In foo Debug.Print member 'Prints "Three" Next End Sub