Home » Arrays, Collections, Lists » How to remove all the items in a collection
How to remove all the items in a collection
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 'Arrays, Collections, Lists - How to remove all the items in a collection 'collections don't offer a native way to remove all the items in a single 'operation, so you're forced to write a loop. Here's a general function 'that does it for you: Sub RemoveAllItems(col As Collection) Do While col.count col.Remove 1 Loop End Sub 'A faster way to remove all the items in a Collection is to destroy the 'Collection object itself by setting it to Nothing or to another fresh, 'new instance: 'Both these lines destroy the current contents of the Collection. Set EmployeeNames = Nothing Set EmployeeNames = New Collection 'This approach works only if there isn't any other object variable pointing 'to the Collection object, however. |
Enjoy this article?
Filed under: Arrays, Collections, Lists
Leave a comment