tags:

views:

77

answers:

1

i have an array like this:

Dim aFirstArray() As Variant

how do i clear the entire array>?

what about a collection?

+3  A: 

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
Sarfraz
what about a collection?
I__
@I: see my updated answer please.
Sarfraz
Just a quick note, at least for VBA, you can't ReDim an array that was declared with dimensions.
KevenDenen
+1 @KevenDenen that's true, but the array in the original question wasn't declared with dimensions. @Sarfraz great answer but your link is for VB.Net. I can't find a link for VBA. Here's the link for the VB6 manual http://msdn.microsoft.com/en-us/library/aa243360(v=VS.60).aspx
MarkJ