Looping Through the Elements of a Custom Collection : Collection « Data Type « VBA / Excel / Access / Word






Looping Through the Elements of a Custom Collection

 
Sub LoopThroughCollection()
   Dim colSports As New Collection
   Dim varSport As Variant
   colSports.Add "Basketball"
   colSports.Add "Skiing"
   colSports.Add "Skating", Before:=1
   colSports.Add "Hockey", After:=2
   For Each varSport In colSports
      Debug.Print varSport
   Next varSport
End Sub

 








Related examples in the same category

1.Create collection
2.Removing Objects from a Collection
3.Creating and Working with Custom Collections
4.Accessing an Item in a Custom Collection
5.Item method is the default method of the Collection object
6.Refer to an item in a collection using its unique key
7.Removing Items from a Custom Collection
8.Remove element with the key
9.Remove all the elements of a collection in two ways:
10.Iterating Through the Elements of a Custom Collection: use the For...Each loop to iterate through the items in a collection
11.Adding Items to a Custom Collection
12.Referencing Items in a Custom Collection
13.Using a Collection to Manipulate Multiple Instances of the FileInformation Class