How to clear the entire array?

calendar_today Asked Jun 10, 2010
thumb_up 58 upvotes
history Updated April 16, 2026

Question posted 2010 ยท +29 upvotes

I have an array like this:

Dim aFirstArray() As Variant

How do I clear the entire array?
What about a collection?

Accepted answer +58 upvotes

You can either use the Erase or ReDim statements to clear the array:

Dim threeDimArray(9, 9, 9), twoDimArray(9, 9) As Integer
Erase threeDimArray, twoDimArray
ReDim threeDimArray(4, 4, 9)

See the different usage of each method here.

Update

To remove a collection, you iterate over its items and use the remove method:

For i = 1 to MyCollection.Count
  MyCollection.Remove 1 ' Remove first item
Next i

2 code variants in this answer

  • Variant 1 โ€” 3 lines, starts with Dim threeDimArray(9, 9, 9), twoDimArray(9, 9) As Integer
  • Variant 2 โ€” 3 lines, starts with For i = 1 to MyCollection.Count

Top excel-vba Q&A (6)

+58 upvotes ranks this answer #1 out of 136 excel-vba solutions on this site โ€” top 1%.