VBA Erase Function

The Excel VBA Erase function clears the contents of all provided VBA Arrays You n.

VBA Erase Function Syntax

 Erase( ArrayName [, ArrayName] )

where ArrayName is the VBA Array variable name which contents you want to erase. You can provide also additional VBA Arrays after the comma as additional arguments.

Example usage create a VBA Erase

Below a simple example of erasing the contents of 2 VBA Arrays:

Dim arr(10) As Variant, arr1(20) As Variant
arr(1) = 10
arr1(10) = 10
Debug.Print arr(1) 'Result: 10
Debug.Print arr1(10) 'Result: 10

Erase arr, arr1 'Erase both arrays

Debug.Print arr(1) 'Result: Empty
Debug.Print arr1(10) 'Result: Empty

You can also erase only a single array:

Dim arr(10) As Variant
arr(1) = 10
Debug.Print arr(1) 'Result: 10

Erase arr, arr1 'Erase both arrays

Debug.Print arr(1) 'Result: Empty