Comment clear the entire array?

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Comment clear the entire array?

Message par Clippy »

I have an array like this:

```
Dim aFirstArray() As Variant

```

How do I clear the entire array?
What about a collection?
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Comment clear the entire array?

Message par Clippy »

You can either use the `Erase` or `ReDim` statements to clear the array. Examples of each are shown in [the MSDN documentation](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/erase-statement). For example:

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

```

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

```
Répondre

Revenir à « Excel & VBA »