How to Fix Excel List Box Always Selecting an Item After Refreshing
Question details
The user needs to prevent an Excel form list box from automatically highlighting an item after it is cleared and repopulated via VBA.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Clearing and repopulating an Excel form list box via a VBA macro during normal execution.
- Observed behavior
- Setting Value or ListIndex to an empty state (-1) successfully clears the selection while debugging, but an item remains incorrectly highlighted when the code runs normally.
Verify if any Change or Click event handlers are attached to your list box in the VBA editor, as these events might be triggered unexpectedly during the repopulation process.
Adjust VBA Timing and Event Execution Order
Reordering your code and temporarily disabling events ensures the list box is fully repopulated before setting its unselected state, eliminating execution speed differences between debugging and normal runs.
The discrepancy between debugging and normal execution is primarily caused by VBA execution speed and UI timing. During normal execution, the list box might regain focus or trigger a background event immediately after repopulation, which forces a default selection. Explicitly controlling events and the exact order of operations will resolve this behavior.
At the very beginning of your VBA procedure, add the line Application.EnableEvents = False. This prevents other background events from firing and assigning focus while the list box is updating.
Use the .Clear method on your list box control to remove existing data, then execute your standard loop or array assignment to load the new items.
Immediately after the repopulation process has completely finished, explicitly clear any highlighted selections by adding the code ListBox1.ListIndex = -1 (replace ListBox1 with your actual control name).
Before exiting the sub routine, restore normal event handling by adding Application.EnableEvents = True to ensure the rest of your workbook functions correctly.

Create and Manage Form Controls Seamlessly in WPS Office
WPS Spreadsheet offers excellent support for form controls and VBA macros. You can insert, design, and run your programmed list boxes with high compatibility and fast execution speeds.
- 1. Enable the Developer Tab: Open WPS Spreadsheet, go to the top ribbon, and click on 'Developer' to access macro and form control tools.
- 2. Insert a List Box: Click the 'Insert' dropdown in the Developer tab, and select the 'List Box' icon from the Form Controls section.
- 3. Draw and format the control: Click and drag on your worksheet to draw the list box, then right-click it to assign a macro or access the Format Control properties.
- 4. Edit the Macro: Click 'Visual Basic' in the Developer tab to open the VBA editor and paste your optimized ListIndex code.

Frequently Asked Questions
Why does ListIndex = -1 work in VBA debug mode but fail during a normal run?
In debug mode, execution pauses between lines, giving the Excel interface enough time to fully render the list box and clear pending events. During a normal macro run, the execution is instantaneous, and overlapping UI refresh events can overwrite your ListIndex setting.
How do I stop my list box from triggering a Change event while repopulating?
You can temporarily disable all event triggers by inserting Application.EnableEvents = False at the top of your code block. Just remember to set it back to True at the end of the script.
Can I run my Excel VBA list box macros in WPS Office?
Yes, the advanced versions of WPS Office fully support VBA macros and ActiveX/Form controls. You can run, edit, and troubleshoot your existing Excel macro files directly within WPS Spreadsheet.




