VBA & Macro Problems

Dynamically Populate an Excel VBA ListBox from a ComboBox

Tauseeq MagsiTauseeq Magsi Nov 13, 2026 870 views

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.

How to Dynamically Populate a ListBox from a ComboBox in Excel VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In WPS Spreadsheets, click Developer > Visual Basic or press Alt+F11 to open the Visual Basic Editor.

2
Open the UserForm module

In the Project Explorer, double-click the UserForm that contains the ComboBox and ListBox.

3
Add the ComboBox Change event

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

4
Match the actual control names

Open the Properties window and replace ComboBox1 and ListBox1 with the exact names used in your UserForm.

5
Run and test

Press F5 or run the macro, select each category in the ComboBox, and confirm the ListBox updates correctly.

ListBox updates cleanly: The ListBox is cleared first each time, so old Fruit items are removed before Vegetable or Starch items are added.
WPS Spreadsheets VBA Support

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. 1. Open WPS Spreadsheets and the workbook: Download WPS Office, open WPS Spreadsheets, and load the macro-enabled Excel workbook (.xlsm or .xls).
  2. 2. Open the Visual Basic Editor: Click Developer > Visual Basic or press Alt+F11 to open the VBA editor.
  3. 3. Locate the UserForm code: In Project Explorer, double-click the UserForm that contains the ComboBox and ListBox.
  4. 4. Add the change event: In the ComboBox Change event, use Me.ListBox1.Clear and Me.ListBox1.AddItem based on Me.ComboBox1.Value.
  5. 5. Run and test the UserForm: Run the UserForm, select a category, and verify the ListBox displays the matching items.
Fixes the Excel VBA object-not-specified error in WPS SpreadsheetsUses the familiar Visual Basic Editor and UserForm controlsSupports Excel macro-enabled formats such as .xlsm and .xlsFree, lightweight Microsoft Office alternative for VBA spreadsheet tasksRuns existing Excel macros without a separate Office license
microsoft office alternative - wps office

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.