VBA & Macro Problems

Populate an Excel UserForm TextBox from Another ListBox Column

Khadija KhanKhadija Khan Nov 18, 2026 870 views

Question details

Display a related worksheet value in a UserForm TextBox when a user selects an item in a ListBox.

Populate an Excel UserForm TextBox from Another ListBox Column
Product
Microsoft Excel
Device & OS
not provided
Scenario
A UserForm ListBox contains values from a worksheet, while the value to display is stored in a different, non-contiguous column.
Observed behavior
Selecting a ListBox item should look up its source row and populate the TextBox with the related value.
Before you start

Identify the worksheet, the column containing the ListBox lookup values, and the column containing the values to display. Confirm the UserForm control names and save the workbook in a macro-enabled format such as .xlsm.

Solution 1Recommended

Look up the selected ListBox value in the click event

Use an exact-match lookup to find the selected item and return a value from another worksheet column.

This example looks for the first ListBox column's value in Sheet1!A2:A1000 and returns the corresponding value from column D. Change the worksheet name, range, column number, and control names to match your workbook.

1
Open the UserForm code

In Excel, press Alt+F11 to open the Visual Basic Editor. In Project Explorer, double-click your UserForm, then double-click ListBox1 to open its Click event.

2
Add the lookup code

Replace the ListBox1_Click procedure with this code: Private Sub ListBox1_Click() Dim ws As Worksheet Dim matchPos As Variant Dim selectedValue As Variant If Me.ListBox1.ListIndex < 0 Then Me.TextBox1.Value = "" Exit Sub End If Set ws = ThisWorkbook.Worksheets("Sheet1") selectedValue = Me.ListBox1.List(Me.ListBox1.ListIndex, 0) matchPos = Application.Match(selectedValue, ws.Range("A2:A1000"), 0) If IsError(matchPos) Then Me.TextBox1.Value = "" Else Me.TextBox1.Value = ws.Cells(CLng(matchPos) + 1, 4).Value End If End Sub

3
Adapt and test the lookup

Change Sheet1, A2:A1000, and the column number 4 as needed. If the lookup range starts on a row other than 2, adjust the + 1 offset to the starting row minus 1. Run the UserForm and click a ListBox item to check TextBox1.

Look up the selected ListBox value in the click event
Use unique lookup values: Match returns the first exact match. If lookup values are duplicated, use a unique identifier to ensure the correct row is returned. An item with no match clears the TextBox.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Excel format compatibility to help you move existing files. It does not fix an Excel UserForm macro; check VBA and UserForm compatibility before relying on existing automation.

Open and edit Excel spreadsheet data in a familiar interfaceCompatible with Microsoft Excel formats including XLSXFree, lightweight office tools for everyday workMove existing spreadsheets into WPS Office without starting over
microsoft office alternative - wps office

Frequently Asked Questions

Where do I put the ListBox lookup code?

Open the Visual Basic Editor with Alt+F11, open the UserForm in Project Explorer, and add the code to its ListBox1_Click event. Use your actual ListBox name if it differs.

Can the return column be separated from the lookup column?

Yes. In the example, Application.Match searches column A, and ws.Cells retrieves the value from column D. Change the column number in ws.Cells to use another return column.

What happens if the selected item is not found?

Application.Match returns an error value. The IsError check handles it by clearing TextBox1; you can add a MsgBox in that branch if you want to notify the user.

How do I use a different ListBox column as the lookup value?

Change the second argument in ListBox1.List(ListBox1.ListIndex, 0). ListBox column indexes start at 0, so use 1 for the second column.