Dynamically Populate an Excel VBA ListBox from a ComboBox
Question details
The user needs an Excel VBA ListBox to update dynamically when a category is selected in a ComboBox, but the existing code raises an object-not-specified compile or runtime error.

- Product
- WPS Spreadsheets
- Device & OS
- not provided
- Scenario
- A UserForm contains a ComboBox for categories and a ListBox that should show Fruit, Vegetable, or Starch items based on the selected category.
- Observed behavior
- The ListBox is cleared and items are added with unqualified control names, causing an object-not-specified compile or runtime error.
Open the macro-enabled workbook in WPS Spreadsheets and make sure the Developer tab is visible. Enable macros and open the Visual Basic Editor so you can edit the UserForm code.
Reference UserForm controls explicitly and clear the ListBox before adding items
Use this when the ListBox must update immediately after a ComboBox selection and the current code fails with an object-not-specified error.
The object-not-specified error usually means the code refers to a control without qualifying it with the UserForm. Always use Me.ControlName so VBA resolves the control on the active UserForm.
In WPS Spreadsheets, click Developer > Visual Basic or press Alt+F11 to open the Visual Basic Editor.
In the Project Explorer, double-click the UserForm that contains the ComboBox and ListBox.
Insert or edit the ComboBox Change event and reference the controls explicitly. Use: Me.ListBox1.Clear; Select Case Me.ComboBox1.Value; Case "Fruit": Me.ListBox1.AddItem "Apple"; Case "Vegetable": Me.ListBox1.AddItem "Carrot"; Case "Starch": Me.ListBox1.AddItem "Rice"; End Select
Open the Properties window and replace ComboBox1 and ListBox1 with the exact names used in your UserForm.
Press F5 or run the macro, select each category in the ComboBox, and confirm the ListBox updates correctly.
Create a formula-based dependent drop-down without VBA
Use this if the workbook does not require VBA and you prefer a formula-driven dynamic list.
Dynamically Populate a ListBox from a ComboBox in WPS Spreadsheets
Use the WPS Spreadsheets Visual Basic Editor to fix the UserForm code, clear the ListBox, and add items based on the ComboBox selection without object-not-specified errors.
- 1. Open WPS Spreadsheets and the workbook: Download WPS Office, open WPS Spreadsheets, and load the macro-enabled Excel workbook (.xlsm or .xls).
- 2. Open the Visual Basic Editor: Click Developer > Visual Basic or press Alt+F11 to open the VBA editor.
- 3. Locate the UserForm code: In Project Explorer, double-click the UserForm that contains the ComboBox and ListBox.
- 4. Add the change event: In the ComboBox Change event, use Me.ListBox1.Clear and Me.ListBox1.AddItem based on Me.ComboBox1.Value.
- 5. Run and test the UserForm: Run the UserForm, select a category, and verify the ListBox displays the matching items.

Frequently Asked Questions
Why does my Excel VBA ListBox not update when I change the ComboBox?
The code usually fails because controls are referenced without the UserForm qualifier. In the ComboBox Change event, use Me.ComboBox1.Value and Me.ListBox1.Clear before adding items with Me.ListBox1.AddItem.
How do I clear a ListBox before adding new items in VBA?
Call Me.ListBox1.Clear at the top of the ComboBox Change event. This removes previous Fruit, Vegetable, or Starch entries and prevents duplicates.
Can I create a dependent drop-down without VBA in WPS Spreadsheets?
Yes. Use Data Validation with a List source and the INDIRECT function, or create named ranges for each category and reference the category cell.
Which control names should I use in the ListBox VBA code?
Replace ComboBox1 and ListBox1 with the exact names shown in the Properties window of your UserForm. Matching names prevents object-not-specified errors.
Does this VBA UserForm code work in WPS Spreadsheets?
WPS Spreadsheets supports VBA macros and the Visual Basic Editor, but some ActiveX features may differ by version. Test the UserForm in your installed version.




