VBA & Macro Problems

How to Clear All Data from a VBA UserForm ListBox in Excel

Huma Ashraf ChHuma Ashraf Ch Nov 2, 2026 869 views

Question details

The user needs a reliable method to remove every item from a VBA UserForm ListBox to reset the form, avoiding compile or index errors caused by incorrect item removal logic.

How to Clear All Data from a VBA UserForm ListBox
Product
Excel VBA
Device & OS
not provided
Scenario
Resetting a UserForm for a new time period by emptying the ListBox entirely rather than just removing highlighted items.
Observed behavior
Attempting to remove only selected items or using a standard forward loop results in compile errors, index out of bounds errors, or undefined variable references.
Before you start

Before modifying your VBA code, ensure your ListBox is not bound to a worksheet range via the RowSource property, as bound ListBoxes cannot be cleared using standard VBA methods.

Solution 1Recommended

Use the ListBox Clear Method

The simplest and most efficient way to remove all items from an unbound ListBox is by using the built-in Clear method.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.

2
Locate your UserForm code

In the Project Explorer panel, right-click the UserForm containing your ListBox and select 'View Code'.

3
Insert the Clear command

Inside the subroutine for your reset button (e.g., Sub cmdClear_Click), type the command 'lstDatabase.Clear'. Ensure you replace 'lstDatabase' with the actual name of your ListBox control.

4
Test the UserForm

Run the UserForm by pressing F5. Click your designated clear button to verify that the ListBox empties completely.

Use the ListBox Clear Method
Fastest Approach: Using the .Clear method is the cleanest one-line solution for instantly resetting any unbound ListBox.
Advanced Macros in WPS Spreadsheet

Manage VBA UserForms with WPS Spreadsheet

WPS Office provides robust support for VBA and Macros, allowing you to create customized UserForms, execute scripts, and automate data tasks seamlessly.

  1. 1. Install WPS Office: Download and install the free WPS Office suite on your computer.
  2. 2. Open your macro workbook: Launch WPS Spreadsheet and open your .xlsm file containing the UserForm.
  3. 3. Access the Developer Tab: Navigate to the Developer tab on the ribbon and click on 'VBA Editor'.
  4. 4. Edit the UserForm: Apply the ListBox Clear method directly within the WPS VBA editor just as you would in Microsoft Excel.
High compatibility with Microsoft Excel (.xlsm) macro-enabled workbooks.Built-in VBA editor for writing and debugging UserForm scripts.Lightweight application footprint for faster data processing.Free to download with an intuitive, familiar user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get an index error when using a standard For loop to remove ListBox items?

When you remove an item, the ListBox's total item count decreases, and the remaining indices shift upwards. A standard forward loop will eventually try to reference an index number that no longer exists, causing a runtime error. You must use a reverse loop (Step -1) to avoid this.

Why doesn't the Selected property clear all items?

The Selected property evaluates whether a user has actively clicked and highlighted an item in the UserForm. If you only target selected items in your code, unhighlighted data will remain in the ListBox.

Can I use the Clear method if my ListBox is populated using the RowSource property?

No. If your ListBox is bound to a worksheet range via the RowSource property, utilizing the .Clear method will produce a 'Permission denied' error. To clear a bound ListBox, you must either delete the data in the source worksheet range or set the RowSource property to an empty string.