VBA & Macro Problems

How to Populate a VBA UserForm ComboBox from Worksheet Headers

John WilsonJohn Wilson Nov 3, 2026 871 views

Question details

The user needs to load specific, non-adjacent worksheet headers (e.g., B1, E1, H1) into a UserForm ComboBox. Upon selection, two text boxes must automatically display data from the last populated row of the corresponding column.

Populate a VBA UserForm ComboBox from Worksheet Headers
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Building a custom VBA data entry or lookup interface to pull records dynamically from specific spreadsheet columns.
Observed behavior
Requires a structured VBA macro to link ComboBox selections to dynamic column data retrieval without pulling in unwanted adjacent headers.
Before you start

Ensure you have the Developer tab enabled in your spreadsheet program and that your UserForm controls (ComboBox1, TextBox1, TextBox2) are properly named before writing the script.

Solution 1Recommended

Use VBA Initialization and Change Events to Map Columns

This solution uses the UserForm_Initialize event to load the specific headers into the ComboBox, and the ComboBox_Change event to dynamically find the last row of the selected column.

To achieve this, you must separate the process into two parts. First, the ComboBox needs to be populated when the form opens. Since the headers are non-adjacent (B1, E1, H1, K1, N1, Q1), you can use an array or manually add each item.

Second, when a user selects a header from the dropdown, the macro must identify which column that header belongs to, find the last used row in that specific column, and output the desired values into the TextBoxes.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor. Insert your UserForm and add one ComboBox and two TextBoxes.

2
Initialize the ComboBox

Double-click the UserForm background to open its code module. Select 'Initialize' from the top-right event dropdown. Write code to loop through an array of your target cells (e.g., Array("B1", "E1", "H1")) and use the ComboBox1.AddItem method to add their values.

3
Set Up the Change Event

Return to the UserForm visual designer and double-click the ComboBox to generate the ComboBox1_Change event. Write a Select Case or If statement that checks the selected value.

4
Find the Last Row and Populate TextBoxes

Inside the Change event, once the correct column is identified, use the formula 'LastRow = Cells(Rows.Count, ColumnIndex).End(xlUp).Row' to find the bottom-most data. Finally, assign 'TextBox1.Text = Cells(LastRow, ColumnIndex).Value' (adjusting offsets as needed for your two text boxes).

Use VBA Initialization and Change Events to Map Columns
Pro Tip: Using the 'End(xlUp)' method is the most reliable way to find the last row in a specific column, as it avoids issues caused by blank cells within the dataset.
Advanced VBA Support in WPS Office

Develop Custom UserForms Seamlessly with WPS Spreadsheet

WPS Office provides robust support for VBA macros and UserForms, allowing you to automate complex tasks and build custom interfaces just like you would in Microsoft Excel.

  1. 1. Open your Spreadsheet: Launch WPS Spreadsheet and open the workbook where you want to build your UserForm.
  2. 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on 'Visual Basic Editor' to open the coding environment.
  3. 3. Create Your UserForm: Right-click in the Project window, select Insert, and choose UserForm. Drag and drop your ComboBox and TextBoxes from the Toolbox.
  4. 4. Add Your Code and Save: Double-click your controls to add the initialization and change event code, then save your file in the macro-enabled .xlsm format.
High compatibility with Microsoft Excel VBA scripts and UserForm controls.Lightweight environment ensures macros execute quickly without lagging.Intuitive Developer tab for easy access to the Visual Basic Editor and form tools.
microsoft office alternative - wps office

Frequently Asked Questions

How do I loop through non-adjacent cells to populate a ComboBox?

You can declare an array containing the specific cell addresses (e.g., Array("B1", "E1", "H1")). Then, use a 'For Each' loop to iterate through the array and apply 'ComboBox.AddItem Range(cellAddress).Value' during the UserForm_Initialize event.

What is the best way to find the last used row in a specific column?

The most robust method in VBA is using 'Cells(Rows.Count, columnIndex).End(xlUp).Row'. This starts from the very bottom of the worksheet and looks upwards, safely finding the last cell with actual data.

Why do my TextBoxes display empty values after selecting a ComboBox item?

This usually happens if the macro selects the wrong column index, or if the last row in that column contains empty formatting or a formula returning a blank string. Verify your column variables and ensure your 'End(xlUp)' logic targets the correct column number.