Prefill an Excel VBA Text Box from a Drop-Down Lookup
Question details
Display the fee for a selected event in a form text box using a 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.
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.
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.
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.
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.
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
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.
In Excel, choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) to retain the VBA code.

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.

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).




