Combobox in VBA UserForms: Setup, Code, and Tips

VBA & macros · Updated November 14, 2026

A ComboBox in a VBA UserForm lets a person choose an item from a drop-down list, and it can also allow typed input if you configure it that way. In the Visual Basic Editor, add a ComboBox from the Toolbox, fill it in the form’s Initialize event, and read the user’s choice from its Value property after checking that an item is selected.

What a UserForm ComboBox does

A ComboBox combines a text box and a list. It is useful when a form needs a compact way to offer a set of choices, such as departments, product names, regions, or status values. A user can open the list and select an entry; depending on the control’s Style setting, they may also be able to type into its text area.

In Excel VBA, a UserForm is a custom dialog created in the Visual Basic Editor. It is different from a ComboBox placed directly on a worksheet: the UserForm control belongs to the form and is managed through VBA events and properties. UserForms are available in desktop Excel, but they do not run in Excel for the web.

A ComboBox is most useful when there are several valid choices and a drop-down saves space. It is less suitable when the user should select several items at once; a ListBox with multiselect enabled is usually a better fit for that job.

Insert the control in a UserForm

In Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11. On a Mac, Option+F11 opens the editor on many keyboards; some require Fn+Option+F11. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon on Windows, or Excel > Preferences/Settings > Ribbon & Toolbar on Mac, then select Developer.

  1. In the Visual Basic Editor, choose Insert > UserForm. The form and Toolbox appear.
  2. Click the ComboBox tool in the Toolbox, then drag on the form to draw the control.
  3. Select the control and set its (Name) property in the Properties window to a useful name, such as cboDepartment.
  4. Set the UserForm’s (Name) property too, if you want a descriptive form name, and use its Caption property for the title shown to the user.
  5. Double-click the form’s blank area to open its code window. This is where you can add the Initialize event procedure.

Use names that communicate what a control contains. A name such as cboDepartment is easier to understand in code than the default ComboBox1, particularly when a form has several controls. The visible label beside the control can say “Department”; the control name is for VBA code and does not need to be shown to the user.

Populate the list when the form opens

For a short, fixed list, you can add entries with the ComboBox’s AddItem method. For a list maintained in a worksheet, read the cells when the form opens. The example below assumes a worksheet named Lists, a header in A1, and department names in A2 downward. Put this code in the UserForm’s code module, replacing cboDepartment if your control has another name.

Private Sub UserForm_Initialize()
    ' Load nonblank department names from the Lists worksheet.
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim r As Long
    Dim itemText As String

    Set ws = ThisWorkbook.Worksheets("Lists")
    Me.cboDepartment.Clear
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    If lastRow < 2 Then Exit Sub

    For r = 2 To lastRow
        itemText = Trim$(CStr(ws.Cells(r, "A").Value))
        If Len(itemText) > 0 Then
            Me.cboDepartment.AddItem itemText
        End If
    Next r
End Sub

UserForm_Initialize runs when the form is loaded, before it is displayed. Clearing the control first prevents duplicate entries if your code initializes it more than once. The loop skips blank cells and trims spaces at the beginning and end of each entry. It assumes the cells contain ordinary values rather than Excel error values; if the source range may contain errors, test for them before converting the cell value to text.

For a tiny fixed list, the body of the loop can instead be replaced by lines such as Me.cboDepartment.AddItem "Sales" and Me.cboDepartment.AddItem "Support". That is quick to set up, but changing the choices then requires editing code. Keeping choices on a worksheet is usually easier for a list that workbook users need to maintain.

Read and validate the selection

To use the chosen item, read the control’s Value property in an event such as a command button’s Click event. Check ListIndex first: it is -1 when no list item is selected, and the first list item has index 0. The following example displays the selected department; it does not write anything to a worksheet.

Private Sub cmdShowDepartment_Click()
    ' Require a list selection before using the value.
    Dim selectedDepartment As String

    If Me.cboDepartment.ListIndex = -1 Then
        MsgBox "Select a department first.", vbExclamation
        Exit Sub
    End If

    selectedDepartment = CStr(Me.cboDepartment.Value)
    MsgBox "Selected department: " & selectedDepartment
End Sub

Change cmdShowDepartment to match the (Name) property of your command button. In a real form, the code after the check could write the choice to a cell, pass it to another procedure, or use it to determine what data to show. If the ComboBox allows typed text, decide whether arbitrary text is acceptable before using Value as if it were a validated list item.

Save a copy of the workbook before running a macro. VBA macros cannot be undone with Ctrl+Z, so a procedure that changes cells or other workbook content may not be reversible through Excel’s Undo command. Save a macro-enabled workbook as an .xlsm file if it needs to retain its VBA project.

Choose the right ComboBox properties

The Properties window can set many options at design time; code can also set properties when the form initializes. These settings affect how the control looks and what values it accepts.

  • Style: fmStyleDropDownCombo allows typing as well as selecting. fmStyleDropDownList limits the user to entries in the list. Choose the list-only style when unrestricted text would cause errors or inconsistent records.
  • MatchRequired: When set to True, the control requires a value that matches an entry in its list. This is relevant when typed input is enabled; it is not a substitute for checking the user’s selection in your own code.
  • MatchEntry: This controls how typing navigates matching list entries. For example, fmMatchEntryComplete completes a typed prefix using a matching item. It does not itself decide whether the entry is valid.
  • BoundColumn: This determines which list column supplies the control’s Value. It is useful when a row contains both a label and an internal identifier.
  • ColumnCount and ColumnWidths: These control how many columns appear and their displayed widths. A narrow or zero-width column can keep an internal code hidden while showing a readable label.

Property values and behavior can depend on the control’s data and setup, so test the form with an empty list, a normal choice, and any typed-input case you intend to allow. Do not assume a displayed label and the value returned by the control are always the same if you configure multiple columns or change BoundColumn.

Use two columns for labels and IDs

A common design stores a readable name beside a stable identifier. For instance, a list might show “North Division” but return the code 204 to other VBA code. A two-column ComboBox can represent both values, provided its column settings and bound column are configured consistently.

For example, set ColumnCount to 2 and BoundColumn to 2, then add each row with the visible name first and the identifier second. In a UserForm procedure, the essential pattern is:

With Me.cboDepartment
    .ColumnCount = 2
    .BoundColumn = 2
    .AddItem "North Division"
    .List(.ListCount - 1, 1) = 204
End With

In this example, the column number used by the List property is zero-based: 0 is the first column and 1 is the second. BoundColumn uses a different convention: 1 means the first column and 2 means the second. That difference is a frequent source of confusion. Set TextColumn if you need to specify which column supplies the text shown in the control, and use ColumnWidths to make the displayed columns readable. Verify both what the user sees and what Value returns before relying on the identifier in later code.

Load from a worksheet: AddItem or RowSource?

There are two common ways to connect a ComboBox to worksheet data. With AddItem, VBA reads values and adds them to the control. This gives you a convenient place to skip blanks, sort or filter entries, and construct multiple columns. The earlier Initialize example uses this approach.

The RowSource property links the list to a worksheet range by address. It can be quick when the source is a simple, fixed range, but it is less flexible than building the list in code. A range that grows or changes may require extra work to keep the source address current. Avoid setting RowSource and also adding the same entries manually unless you deliberately manage both sources; mixing methods can produce confusing or duplicated list contents.

For a workbook-controlled list that changes size, AddItem with a last-row calculation is often straightforward. For a stable range with no special filtering, RowSource can be simpler. Whichever approach you choose, make the worksheet reference explicit and test what happens when the source has no entries. If the sheet is renamed or deleted, code that refers to its old name will fail, so keep the sheet name and code in sync.

Common problems and practical checks

  • The list is empty: Confirm the code is in the UserForm module and named exactly UserForm_Initialize. Check the worksheet name, the source column, and whether your data begins on the row assumed by the code.
  • The form shows duplicates: Clear the ComboBox before repopulating it. Duplicates can appear if an initialization routine is called repeatedly without clearing the existing list.
  • Code reports that a control is missing: Check the control’s (Name) property. Its displayed label or caption does not define the name VBA uses after Me..
  • The selected value is blank or unexpected: Check ListIndex before reading Value. If the ComboBox has multiple columns, inspect BoundColumn and TextColumn; the value may be an ID rather than the visible label.
  • Users can type unwanted values: Set Style to fmStyleDropDownList when only listed choices are valid, or apply suitable validation in code if typed input is needed.
  • The macro does not run: Confirm that macros are permitted by the workbook’s security settings and that the file is saved in a macro-enabled format. Do not enable macros from an untrusted source just to make a form open.

Test the form with realistic cases, not only the first item in the list. Include a blank source range, a long item name, and a user who closes the form without choosing anything. Those checks reveal layout and validation problems before the form is used for routine data entry.

ComboBox versus other ways to choose

A UserForm ComboBox is appropriate when the user should choose one item in a dialog and the list is too long or space-consuming to show all at once. A ListBox is clearer when several choices should remain visible, or when multiple selection is required. A worksheet data-validation list is usually simpler when users can enter data directly in cells and do not need a custom dialog.

A ComboBox placed on a worksheet is another option, but it is not the same as a UserForm ComboBox. Worksheet controls have their own placement and configuration, while a UserForm control is displayed as part of a dialog and normally interacts with form events. Choose based on where the input belongs and how much custom behavior the workbook needs; a UserForm is not automatically better for a simple one-cell choice.

Frequently Asked Questions

How do I add items to a VBA UserForm ComboBox?
Use the control’s AddItem method, commonly inside UserForm_Initialize. For a worksheet-based list, loop through the source cells and add each valid value. Clear the control first if the loading code may run more than once.

How do I get the selected ComboBox value in VBA?
Read the control’s Value property, such as Me.cboDepartment.Value. Check that ListIndex is not -1 first so your code can handle the case where the user has not selected an item.

How can I stop users typing their own entries?
Set the ComboBox Style property to fmStyleDropDownList. This makes the control selection-only, so the user chooses from the listed options rather than entering arbitrary text.

What is the difference between ListIndex and BoundColumn?
ListIndex identifies the selected row and starts at 0; -1 means no row is selected. BoundColumn identifies which column supplies Value and is numbered from 1. They refer to different things and use different numbering.

Can a VBA UserForm ComboBox work in Excel for the web?
No. Excel for the web does not run VBA macros or display VBA UserForms. Use desktop Excel for a VBA-based form, or choose a web-compatible way to collect input if users must work in a browser.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.