How to Populate an Excel Combo Box from Horizontal Data Using VBA
Question details
The user needs to load values arranged horizontally across an Excel worksheet into a UserForm combo box.

- Product
- Excel / WPS Spreadsheet
- Device & OS
- not provided
- Scenario
- Building a custom UserForm and needing to populate a dropdown menu with data that spans across columns (horizontally) instead of standard vertical rows.
- Observed behavior
- Data needs to be automatically read from a dynamic horizontal range and added to the combo box list upon the form's initialization.
Ensure that the Developer tab is enabled in your spreadsheet application and that your workbook is saved as a Macro-Enabled Workbook (.xlsm) to allow VBA code execution.
Use VBA UserForm_Initialize Event to Loop Through Columns
Use a VBA macro to loop through the horizontal range and add each cell's value to the Combo Box when the form loads.
By default, the RowSource property is optimized for vertical data. To populate a combo box with horizontal data, you must utilize the AddItem method within a loop during the UserForm's initialization process.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in your spreadsheet application.
Locate your UserForm in the Project Explorer window on the left. Right-click the form and select 'View Code' to open its code module.
From the dropdown menus at the top of the code window, select the 'UserForm' object on the left and the 'Initialize' procedure on the right to create the Private Sub UserForm_Initialize() event.
Insert the following code inside the subroutine: Dim myList As Range Dim val As Range With ActiveSheet Set myList = .Range(Cells(1, "B"), Cells(1, Columns.Count).End(xlToLeft)) End With For Each val In myList Me.ComboBox1.AddItem val Next val Modify 'Cells(1, "B")' to match the exact row and starting column of your horizontal data.
Press F5 or click the 'Run' button in the toolbar to launch the UserForm and verify that the combo box accurately displays your horizontal data list.

Automate Spreadsheets Effortlessly with WPS Office
WPS Spreadsheet features robust VBA and Macro support, allowing you to create custom UserForms, populate dynamic combo boxes, and streamline your workflow seamlessly.
- 1. Download WPS Office: Install WPS Office to access powerful spreadsheet and macro functionalities for free.
- 2. Enable Macros: Open your workbook in WPS Spreadsheet and navigate to the Developer tab to enable macro processing.
- 3. Open the VBA Editor: Click on the 'Visual Basic' icon in the ribbon or press Alt + F11 to access the built-in VBA editor.
- 4. Implement Your Code: Insert your UserForm and paste the initialization code to dynamically load your horizontal data into the combo box.

Frequently Asked Questions
Can I use the RowSource property for horizontal data in a combo box?
No, the RowSource property is designed specifically for vertical column data. To populate a combo box from a horizontal row, you must use VBA to loop through the horizontal cells and add them individually using the AddItem method.
What if my horizontal data contains blank cells?
If your range includes empty cells, you can add a simple condition within your loop (e.g., If val.Value <> "" Then Me.ComboBox1.AddItem val) to ensure only non-blank values are added to the combo box dropdown.
How do I clear old data from the combo box before reloading?
Include 'Me.ComboBox1.Clear' at the very beginning of your UserForm_Initialize event. This empties the dropdown list before the loop adds the fresh horizontal data, preventing duplicate entries from appearing.




