The Problem (Q-score 29, ranked #6th of 303 in the Excel VBA archive)
The scenario as originally posted in 2010
I have an array like this:
Dim aFirstArray() As Variant
How do I clear the entire array?
What about a collection?
Why community consensus is tight on this one
Across 303 Excel VBA entries in the archive, the accepted answer here holds elite answer (top 10 %%) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — elite answer (top 10 %%) (+58)
4-line Excel VBA pattern (copy-ready)
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
Loop-performance notes specific to this pattern
The loop in the answer iterates in process. On a 2026 Office build, setting Application.ScreenUpdating = False and Application.Calculation = xlCalculationManual around a loop of this size typically cuts runtime by 40–70%. Re-enable both in the Exit handler.
When to Use It — vintage (14+ years old, pre-2013)
A top-10 Excel VBA pattern — why it still holds up
Ranks #6th of 303 in the Excel VBA archive. The only pattern ranked immediately above it is “IF statement: how to leave cell blank if condition is false (""…” — compare both if you’re choosing between approaches.
What changed between 2010 and 2026
The answer is 16 years old. The Excel VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.