VBA & Macro Problems

How to Populate an Excel Combo Box from Horizontal Data Using VBA

Kushani NimanthikaKushani Nimanthika Oct 26, 2026 868 views

Question details

The user needs to load values arranged horizontally across an Excel worksheet into a UserForm combo box.

How to Populate an Excel Combo Box from Horizontal Data Using VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in your spreadsheet application.

2
Access the UserForm Code

Locate your UserForm in the Project Explorer window on the left. Right-click the form and select 'View Code' to open its code module.

3
Insert the Initialization Procedure

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.

4
Paste the Looping Macro

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.

5
Test the UserForm

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.

Use VBA UserForm_Initialize Event to Loop Through Columns
Dynamic Range Adaptation: The code snippet automatically finds the last populated column using 'End(xlToLeft)', ensuring that your combo box stays updated even if you add more data to the horizontal row later.
Advanced Macro Capabilities

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. 1. Download WPS Office: Install WPS Office to access powerful spreadsheet and macro functionalities for free.
  2. 2. Enable Macros: Open your workbook in WPS Spreadsheet and navigate to the Developer tab to enable macro processing.
  3. 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. 4. Implement Your Code: Insert your UserForm and paste the initialization code to dynamically load your horizontal data into the combo box.
Highly compatible with Microsoft Excel VBA syntax and macrosEasily design UserForms with custom controls like combo boxesLightweight software with exceptional processing speedUser-friendly interface for managing complex data arrays
microsoft office alternative - wps office

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.