UserForm VBA Controls: Types, Events, and Examples

VBA & macros · Updated November 18, 2026

UserForm VBA controls are the buttons, text boxes, lists, labels, and other interface elements you place on a VBA UserForm to collect input or show information. In desktop Excel for Microsoft 365 on Windows, you add them in the Visual Basic Editor, set their properties, and write event procedures that determine what happens when someone uses them.

What UserForm Controls Are

A UserForm is a custom dialog window created in Excel’s VBA environment. Controls are the individual parts of that window: a TextBox can accept a name, a ComboBox can offer a department list, and a CommandButton can submit the entries. A control has a visual appearance, configurable properties, and usually events that VBA can respond to.

UserForms are useful when a workbook needs a guided way to enter or review information. For example, a form can ask staff for a customer name, order date, and product category, then validate the entries before writing them to a worksheet. It can also present instructions or choices without asking users to work directly in a grid. A form does not automatically store data, though; its code must specify where values go and what validation is required.

These controls are part of the Microsoft Forms environment used by VBA. They are distinct from the Form Controls and ActiveX controls available from Excel’s worksheet interface. A CommandButton placed on a UserForm is not the same thing as a button added to a worksheet, even though both can run macros.

Common Controls and What They Do

The standard Toolbox includes controls for common input and display tasks. Choose based on the kind of response you need, rather than simply on which control looks familiar.

  • Label: Displays static text, such as a prompt or field name. Users do not type into it.
  • TextBox: Accepts typed text. It can be configured for multiple lines, password-style entry, or limited input, but the code should still validate what the user enters.
  • ComboBox: Provides a drop-down list and can also allow typed text, depending on its Style property. It is useful when a list of choices should take up little space.
  • ListBox: Shows a list of choices directly. Its MultiSelect property can allow one or more selections; code must then read the selected items appropriately.
  • CheckBox: Represents an independent yes-or-no choice, such as “Send a confirmation.” Several check boxes can be selected at once.
  • OptionButton: Represents one choice within a group, such as “Standard” or “Express.” Option buttons in the same parent container are mutually exclusive; a Frame can create a separate group.
  • CommandButton: Runs code when clicked, commonly to submit, cancel, clear, or close the form.
  • Frame: Groups related controls visually and can also define the parent container for a set of option buttons.
  • MultiPage and TabStrip: Organize a larger interface into tabs. A MultiPage contains separate pages for controls, while a TabStrip provides tabs that you coordinate with other controls yourself.
  • Image, SpinButton, and ScrollBar: Display a picture or let users adjust a value through arrows or a scrolling control. These are more specialized and often need code to connect their state to other controls.

Control availability can depend on the Office installation and platform. Older examples may refer to additional or third-party controls that are not present in every current setup. For a form that must travel between computers, prefer standard controls and avoid relying on a control that users may not have installed.

Adding Controls in the Visual Basic Editor

In desktop Excel for Windows, press Alt+F11 to open the Visual Basic Editor. Choose Insert > UserForm to create a blank form. If the Toolbox is not visible, choose View > Toolbox. Select a control in the Toolbox, then click or drag on the form to place it. Use the Properties window to set its name, caption, size, and other settings.

Give controls meaningful names before writing code. For instance, name a name-entry box txtName, a department list cboDepartment, and a submit button cmdSubmit. The Name property is the identifier used by VBA; the Caption property is the text displayed to the user. Naming a button “Submit” in its caption does not automatically make its VBA name cmdSubmit.

To create a button’s click event, double-click the button on the form, or select it and its event in the code window’s drop-down lists. The editor creates a procedure such as cmdSubmit_Click. The event procedure belongs to that UserForm’s code module, not to a worksheet module or a standard module. You can run a form from a macro with a statement such as frmEntry.Show, replacing frmEntry with the form’s actual name.

Excel for the web cannot create or run VBA macros. Excel for Mac has a Visual Basic Editor and supports many VBA UserForm scenarios, but available controls and behavior can differ from Windows. If a workbook will be used on both platforms, check the form on each target version and avoid assuming every Windows-only control or feature is portable.

Important Properties to Configure

Properties define how a control looks and behaves before and during use. The most important are often simple: Name identifies the control in code, Caption supplies visible text for forms and buttons, and Value holds the current value of many input controls. A Label uses Caption for its displayed text, while a TextBox’s Value is the entered content.

Other useful properties include Enabled, which determines whether a control can be used; Visible, which controls whether it appears; and TabIndex, which helps set the order users move through controls with the Tab key. For a TextBox, MultiLine allows multiple lines, while MaxLength can limit the number of characters. For a ComboBox, Style determines whether users can type as well as choose from its list. Set labels and captions to explain the expected input rather than relying on users to infer it from a control’s position.

Properties can be set in the Properties window at design time or in VBA at run time. Design-time settings are easier to inspect and maintain for fixed forms. Code is useful when the content changes, such as loading a list of departments when the form opens. Avoid changing a control’s name after code has been written unless you also update every reference to it.

How Events Connect Controls to VBA

Events are notifications that something has happened. A button’s Click event runs when the user clicks it; a TextBox’s Change event can run when its content changes; and a UserForm’s Initialize event is commonly used to prepare the form before it is displayed. The event procedure is where you put the action, such as checking required fields or loading a list.

Here is a small example for a form named frmEntry with controls named txtName, cboDepartment, and lblStatus, plus a button named cmdSubmit. It loads a short list when the form initializes and displays a confirmation after basic validation. The example does not write to a worksheet.

Option Explicit

Private Sub UserForm_Initialize()
    ' Load the available choices when the form opens.
    With cboDepartment
        .Clear
        .AddItem "Sales"
        .AddItem "Support"
        .AddItem "Operations"
    End With
    lblStatus.Caption = "Enter a name and choose a department."
End Sub

Private Sub cmdSubmit_Click()
    Dim userName As String
    Dim department As String

    userName = Trim$(txtName.Value)
    department = Trim$(cboDepartment.Value)

    If Len(userName) = 0 Then
        lblStatus.Caption = "Enter a name before submitting."
        txtName.SetFocus
        Exit Sub
    End If

    If Len(department) = 0 Then
        lblStatus.Caption = "Choose a department before submitting."
        cboDepartment.SetFocus
        Exit Sub
    End If

    ' Confirm the values; saving them requires additional code.
    MsgBox "Ready to submit: " & userName & " - " & department, vbInformation
End Sub

In actual VBA, the ampersands in the final line join text and variables; the HTML encoding shown in the code block represents the literal VBA operator. The validation stops the procedure when either required field is blank. A real submission routine would add a clearly defined destination, such as a new row in a named worksheet table, and should check that destination before changing workbook data.

Save a copy of the workbook before running a macro that changes data. VBA macros cannot be undone with Ctrl+Z, and a form’s controls do not provide automatic rollback. On Windows, Ctrl+Z is the usual Undo shortcut; on Mac, the equivalent is Command+Z, but neither restores changes made by a macro.

Choosing a Control for the Job

Match the control to the answer format and the risk of invalid input. A ComboBox with a fixed list reduces spelling variations, while a TextBox is better when answers are open-ended. A CheckBox suits independent options; OptionButtons suit one choice from a small, exclusive set. A ListBox can be clearer than a drop-down when users should compare several options at once.

Consider the user’s path through the form as well. Place a short prompt beside each input, use Frames to make groups understandable, and put the primary action in a predictable location. Arrange the TabIndex order to follow the visual reading order, so keyboard users can complete the form without repeatedly reaching for a mouse. Keep the form compact, but do not make text or buttons so small that they are difficult to read or select.

For example, an order-entry form might use TextBoxes for a customer reference and quantity, a ComboBox for a product category, CheckBoxes for optional services, and a CommandButton to validate and add the order to a table. If quantity must be a positive whole number, the TextBox alone cannot guarantee that; the click event must check the value and explain how to correct it. A visually suitable control is not a substitute for validation.

Common Problems and Practical Fixes

  • “Method or data member not found” after renaming: Check that code uses the control’s current Name property and that the procedure is in the correct form module.
  • A list is empty: Confirm that the code populates it, that the initialization event belongs to the correct form, and that later code is not clearing it again.
  • A click does nothing: Check that the procedure name matches the control’s name and event, for example cmdSubmit_Click, and that macros are permitted by the workbook’s security settings.
  • Option buttons allow unexpected combinations: They may be in different parent containers. Put buttons that belong to one exclusive group inside the same Frame.
  • Input causes a type mismatch: TextBox values are text, even when they look like numbers or dates. Validate and convert them deliberately before using them in calculations or storing them.
  • The form looks different on another computer: Differences in display scaling, fonts, Office versions, or platform support can affect layout. Test on the computers and versions that will actually use the workbook.

Use workbook copies while developing, and test empty inputs, unusual characters, long entries, and canceled actions. If a form writes to a worksheet, test what happens when the destination sheet is protected, missing, or already contains data. These cases reveal problems that a happy-path click-through will not.

Frequently Asked Questions

How do I add a control to an Excel UserForm?
Open the Visual Basic Editor, insert or select a UserForm, show the Toolbox if needed, and click or drag a control onto the form. Set its Name and other properties in the Properties window.

What is the difference between Name and Caption?
Name is the identifier VBA uses to refer to the control, such as cmdSubmit. Caption is visible text, such as “Submit,” shown on a button or label.

Can a UserForm control write data to a worksheet by itself?
No. A control holds or displays a value, but VBA code must validate that value and write it to a worksheet or another destination. A button often triggers that code.

Can Excel for the web run UserForm VBA?
No. Excel for the web does not run VBA macros. Use desktop Excel to run a VBA UserForm, and check compatibility separately if the workbook will be opened on Mac.

Are UserForm controls the same as worksheet buttons?
No. UserForm controls belong to a dialog form and are managed through the VBA form designer. Worksheet buttons and other worksheet controls are placed on a sheet and have different setup and interaction patterns.

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.