VBA & Macro Problems

Prefill an Excel VBA Text Box from a Drop-Down Lookup

Steve KSteve K Nov 25, 2026 869 views

Question details

Display the fee for a selected event in a form text box using a lookup.

Prefill an Excel VBA Text Box from a Drop-Down Lookup
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A user selects an event from a form drop-down and wants its fee to appear automatically.
Observed behavior
The desired result is a text box that updates with the matching fee whenever the event selection changes.
Before you start

Identify the drop-down and text box control names, and locate the worksheet range containing event names and fees. The example assumes an Excel VBA UserForm and a two-column table with event names in the first column.

Solution 1Recommended

Look up the fee in the UserForm drop-down's Change event

Use this approach to refresh the fee automatically when the selected event changes.

1
Prepare the lookup table

On a worksheet named Fees, put event names in column A and their fees in column B, starting in row 2. Adjust the worksheet name and range in the code if your table is elsewhere.

2
Open the drop-down event

In Excel, open Developer > Visual Basic, select your UserForm, and double-click the event drop-down to open its Change event. This example uses a ComboBox named cboEvent and a text box named txtFee.

3
Add the lookup code

Replace the Change event procedure with the following, adjusting control names and the range to match your workbook: Private Sub cboEvent_Change() Dim fee As Variant If IsNull(Me.cboEvent.Value) Then Me.txtFee.Value = "" Exit Sub End If If Trim$(CStr(Me.cboEvent.Value)) = "" Then Me.txtFee.Value = "" Exit Sub End If fee = Application.VLookup(Me.cboEvent.Value, _ ThisWorkbook.Worksheets("Fees").Range("A2:B100"), 2, False) If IsError(fee) Then Me.txtFee.Value = "" Else Me.txtFee.Value = CStr(fee) End If End Sub

4
Test the form

Run the UserForm from the Visual Basic editor and select an event. Confirm that the fee appears, then test a blank or unmatched selection to confirm that the text box clears.

5
Save the macro

In Excel, choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) to retain the VBA code.

Look up the fee in the UserForm drop-down's Change event
Match the code to your form: VLOOKUP uses an exact match and searches the first column of the specified range. This example is for a UserForm ComboBox; worksheet controls require a different event procedure.
Free Microsoft Office alternative

Manage event and fee tables in WPS Spreadsheets

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for editing event and fee tables. Its Microsoft Office format support makes it easy to move existing files, although it does not fix Excel VBA issues and macro support can vary by version.

Edit event lists and fee tables in a familiar spreadsheet interface.Open and edit Microsoft Excel formats such as XLSX.Use a free, lightweight Office alternative for everyday spreadsheet work.
microsoft office alternative - wps office

Frequently Asked Questions

Where should I put the lookup code?

In the Visual Basic editor, open the UserForm and place it in the event drop-down's Change procedure. This runs the lookup when the drop-down value changes.

Why is the fee text box blank after I select an event?

Check that the selected event matches a value in the first column of Fees!A2:B100 and that the fee is in the second column. Also update the sheet name, range, and control names in the code to match your workbook.

What happens if an event is not found?

Application.VLookup returns an error value. The IsError check in the example clears txtFee rather than displaying an old fee.

How do I keep the VBA code when I save the workbook?

Choose File > Save As in Excel and save the file as an Excel Macro-Enabled Workbook (*.xlsm).