Return to VBA Code Examples

VBA Clear Array – Erase Function

This tutorial will teach you how to clear an Array in VBA.

Clear Entire Array

To clear an entire array, you can use the Erase Statement:

In practice:

Resize and Clear Array

If your Array is dynamic (A dynamic array is an array that can be resized, as opposed to a static array which can not be resized), you can use the ReDim Command to resize the array, clearing the entire array of values.

Full Example:

Clear Part of an Array

As mentioned above, the ReDim Command will resize an array, clearing all values from the array.  Instead you can use ReDim Preserve to resize the array, preserving any existing values. In practice, this can be used to quickly clear part of an array.

Full Example:

Loop Through Entire Array – Resetting Values

Instead of clearing array values using Erase or ReDim, you could loop through the entire array, resetting each value.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!