Excel UserForm Initialize: How It Works and How to Use It

VBA & macros · Updated November 17, 2026

In Excel VBA, UserForm_Initialize is the event procedure that runs when a UserForm instance is loaded, before the form is displayed. Put one-time setup there—for example, setting default values or filling a drop-down list—then show the form with its Show method.

What the Initialize event does

A UserForm is a custom VBA dialog box that you design in the Visual Basic Editor. Its Initialize event gives you a place to prepare the form’s controls before a user can interact with them. The event procedure belongs in that form’s own code module, not in a worksheet module or a standard module.

Typical setup includes clearing or filling a ComboBox, choosing an initial option, setting a date or instruction in a TextBox, and configuring control properties. Keeping this work in one event procedure is usually easier to maintain than scattering setup code across buttons or worksheet events.

Initialize is an event, not a general Excel worksheet function and not a command that a user types into a cell. The event procedure’s name must match the form’s code name and the event name. For a form named UserForm1, the procedure is normally Private Sub UserForm_Initialize().

When UserForm_Initialize runs

VBA raises Initialize when it loads a particular UserForm instance. A direct Load UserForm1 statement loads the form without displaying it, and the event runs as part of that load. Calling UserForm1.Show on an unloaded default instance loads it automatically, so Initialize runs before the form appears.

The distinction between loading and showing matters. Loading prepares the instance; showing makes it visible. If code loads a form, hides it, and later shows that same still-loaded instance, Initialize does not run again just because it is shown again. Hiding keeps the instance loaded. Unloading it removes that instance, so loading it again causes a fresh Initialize event.

That lifecycle makes Initialize a good home for defaults that should be set once per form instance. It is not necessarily the right place for work that must refresh every time the user returns to a still-loaded form. For that, consider the Activate event or an explicit refresh procedure, depending on when the data should be updated.

How to add the event procedure

  1. In desktop Excel for Windows, open the workbook and press Alt+F11 to open the Visual Basic Editor. On a Mac, use Option+F11; depending on the keyboard, you may also need the Fn key.
  2. In the Project Explorer, locate the workbook’s Forms folder and double-click the UserForm you want to prepare. If the Project Explorer is hidden, use View > Project Explorer in the editor.
  3. Open the form’s code window. In its left object list, choose UserForm; in the right procedure list, choose Initialize. The editor creates the event procedure for that form.
  4. Enter setup statements between the procedure’s opening and closing lines. Use the form designer’s Properties window to confirm the names of controls you refer to in code.

The menu and editor appearance can vary slightly between Excel releases and operating systems, but the event procedure must still be in the UserForm’s code module. If the editor creates a different event procedure, check that you selected the UserForm object and the Initialize event, rather than a control such as a button.

A practical initialization example

Suppose a form contains a ComboBox named cboDepartment and a TextBox named txtStatus. This event clears any existing list entries, adds three choices, selects the first one, and sets a short initial status:

Private Sub UserForm_Initialize()
    ' Prepare the department list for this form instance.
    With Me.cboDepartment
        .Clear
        .AddItem "Sales"
        .AddItem "Operations"
        .AddItem "Support"
        .ListIndex = 0
    End With

    ' Show an initial instruction in the status box.
    Me.txtStatus.Value = "Choose a department."
End Sub

Use the actual names shown in the Properties window; control names are not interchangeable with the labels displayed beside them. Setting ListIndex to zero selects the first list item, because list positions are zero-based. If the list might be empty, do not set the index to zero unless you have first ensured that at least one item was added.

To display a form from a standard module, a simple macro can call its default instance:

Public Sub OpenDepartmentForm()
    ' Display the form; Excel loads it first if necessary.
    UserForm1.Show
End Sub

Before running VBA, save a copy of the workbook. Macros can make changes that Ctrl+Z cannot undo. Save a workbook containing VBA in a macro-enabled format such as .xlsm, and run macros only in workbooks you trust.

Initialize compared with Activate

UserForm_Initialize and UserForm_Activate are different events. Initialize is tied to loading an instance. Activate occurs when the form becomes the active window, which can happen again after another window or dialog has taken focus. Therefore, Activate can run more than once while the same form instance remains loaded.

Use Initialize for stable setup such as adding fixed choices or setting a starting value. Use Activate when an action is specifically needed as the form becomes active—for instance, refreshing information that may have changed while the user was elsewhere. Avoid putting the same list-building code in both events unless there is a clear reason; otherwise, repeated activation may duplicate list entries or reset the user’s selections.

If you need to refresh only after a particular action, an explicit procedure such as RefreshFormData, called from the relevant button or workflow, can be clearer than relying on Activate. The right choice depends on whether the information should be initialized once, refreshed whenever the form activates, or updated only on demand.

Loading data and choosing where it comes from

Fixed choices can be added directly in Initialize, as in the example. If the choices come from a worksheet, the event can read a defined range or a table and add its values to the ComboBox. This is useful when a workbook’s list changes and non-programmers need to maintain it in cells rather than edit VBA.

Before reading worksheet data, decide what should happen if the source range is empty, contains blank cells, or includes a header. A robust routine skips or handles blanks intentionally and avoids adding the header as a selectable choice. Also consider whether the form should read the list once at load time or refresh it when activated; that decision affects whether changes made after loading appear immediately.

For larger data sources or slow operations, keep the Initialize procedure focused. A long-running event delays the form from appearing and can make Excel seem unresponsive. Move reusable work into a separate procedure, and show a clear error message if a required source sheet or range cannot be found rather than allowing a confusing failure later.

Common problems and how to diagnose them

  • The event never runs: Confirm that the procedure is in the correct UserForm module and named exactly UserForm_Initialize. A similarly named procedure in a standard module is not the form event.
  • The code runs only the first time: The form may still be loaded. Hide makes a form invisible but does not unload it, so showing that same instance again does not repeat Initialize.
  • A control name is not recognized: Check the control’s (Name) property, not its displayed caption. A misspelled name or a reference to a control on another form can cause a compile or run-time error.
  • The list shows duplicates: The code may be adding entries in Activate or in another procedure that runs repeatedly without clearing the list. Clear the list before rebuilding it when replacement, rather than accumulation, is intended.
  • The form opens with no selected choice: Verify that an item was actually added before setting ListIndex. A blank or missing source range may leave the list empty.

For debugging, place the cursor in the event procedure and use the editor’s debugging tools, such as setting a breakpoint and stepping through code. Check the values and control names at the point where the problem occurs. A compile error often points to syntax or naming; a run-time error may instead indicate a missing worksheet, an invalid range, or an operation that is not valid for the control’s current state.

Excel version and platform considerations

UserForms are part of Excel desktop VBA, not a feature that runs in Excel for the web. A workbook can contain VBA code when opened in a browser, but the browser version does not execute that VBA or display its UserForms. Open the workbook in the desktop app to use the form.

Excel for Mac has a Visual Basic Editor and supports VBA, but the interface and some control capabilities differ from Windows. In particular, ActiveX controls are not supported on Mac. A traditional VBA UserForm uses Microsoft Forms controls, and control availability or behavior can still vary by platform, so test a workbook on each desktop platform where it must be used. If a form depends on Windows-only components, document that requirement or provide another interface.

Frequently Asked Questions

Does UserForm_Initialize run every time I show the form?
No. It runs when that form instance is loaded. Showing an already loaded instance again does not by itself rerun Initialize; unloading and loading a new instance does.

What is the difference between Load and Show?
Load prepares a form instance without making it visible. Show displays it and loads it first if needed. Initialize runs during loading, before the form is shown.

Should I put code in Initialize or Activate?
Use Initialize for setup that belongs to a newly loaded instance. Use Activate for work that should happen when the form becomes active, including later activations, or use a separate refresh procedure when updates should happen only on demand.

Why does my form keep old values after I close it?
If the code uses Hide, the form remains loaded with its control values intact. Use Unload when the instance should be removed and initialized afresh next time, or deliberately reset the controls in a separate procedure.

Can I use a UserForm in Excel for the web?
No. Excel for the web does not run VBA macros or show VBA UserForms. Use desktop Excel for that workflow, or choose a web-compatible way to collect input.

Can Initialize refer to cells on a worksheet?
Yes. VBA in the form module can read worksheet data during initialization. Qualify worksheet and range references clearly, and account for missing sheets, empty ranges, and headers so the form does not fail or populate misleading choices.

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.