To control an Excel VBA UserForm’s position, set its StartUpPosition property to 0 - Manual, then assign its Left and Top properties before it appears. For example, setting both to 100 places the form roughly 100 points from the upper-left of the screen; use 2 - CenterScreen if you simply want it centered.
What the position settings mean
A UserForm’s StartUpPosition property decides how Excel positions the form when it opens. In the Visual Basic Editor, select the form and find this property in the Properties window. Its available values are:
0 - Manual: use the form’sLeftandTopcoordinates.1 - CenterOwner: center the form over its owner window, commonly the Excel window that opened it.2 - CenterScreen: center the form on the screen.3 - Windows Default: let Windows choose the initial position.
The setting matters because manually assigning coordinates while another startup mode is active may not give the expected result: Excel or Windows can apply the selected startup behavior when the form is shown. Choose Manual when exact placement is important. The setting can be chosen in the Properties window at design time or assigned in VBA before setting the coordinates.
Set the position in the Visual Basic Editor
For a fixed location that does not depend on the workbook window, set the properties on the UserForm itself:
- Open the workbook in desktop Excel and press
Alt+F11to open the Visual Basic Editor on Windows. - In Project Explorer, select the UserForm. If the Properties window is hidden, press
F4. - Set
StartUpPositionto0 - Manual. - Set
LeftandTopto the desired positions. These values are measured in points, not pixels. - Run the form and adjust the values if necessary.
For example, a Left value of 120 and a Top value of 80 requests a position 120 points from the left and 80 points from the top. A point is a typographic unit: 72 points equal one inch. These are screen-position coordinates, not worksheet row and column coordinates. Moving a worksheet cell, scrolling, or changing the active sheet does not itself reposition a UserForm.
Position the form with VBA
For a position calculated when the form opens, use its Initialize event. The example below centers the form over the Excel application window. It assumes Excel is open and the form is being displayed from that Excel instance.
Private Sub UserForm_Initialize()
Dim targetLeft As Double
Dim targetTop As Double
' Use manual placement before assigning coordinates.
Me.StartUpPosition = 0
' Center the form within the Excel application window.
targetLeft = Application.Left + (Application.Width - Me.Width) / 2
targetTop = Application.Top + (Application.Height - Me.Height) / 2
Me.Left = targetLeft
Me.Top = targetTop
End Sub
Put this event procedure in the form’s code module, not in a worksheet or standard module. The Me keyword refers to the current form. Application.Left and Application.Top describe Excel’s position, while its Width and Height and the form’s Width and Height let the code calculate a centered location. This gives a position relative to Excel’s window rather than the entire display. If the Excel window is partly off-screen, the resulting form may also be partly off-screen.
Before running a macro, save a copy of the workbook. VBA actions cannot be undone with Ctrl+Z. To show the form, run a procedure such as UserForm1.Show from a suitable macro; substitute the actual name of your form.
Choose between screen and Excel-window centering
Centering on the screen and centering on Excel are different goals. CenterScreen aims for the display’s center, whether Excel is maximized or occupying only part of it. CenterOwner aims to keep the form associated with the window that opened it. Calculating coordinates from Application.Left, Application.Top, Application.Width, and Application.Height is another option when you want to control the relationship to the Excel window explicitly.
- Choose
CenterScreenfor a simple, general-purpose dialog that should be easy to find. - Choose
CenterOwnerwhen the form should appear in relation to its owner window without a custom calculation. - Choose Manual and fixed coordinates for a deliberately consistent location, such as a form near a screen corner.
- Use a calculated Manual position when the form should follow Excel’s current location or be centered within its current window.
Do not assume that centering over Excel means centering over the active worksheet or a selected cell. Excel’s application window is the reference, not the grid. If a form is opened modelessly, the user can continue working in Excel while it remains visible; its starting position still comes from the form’s startup setting or coordinates.
Points, pixels, and screen scaling
UserForm position and size properties use points. Windows display scaling, monitor resolution, and differences between monitors can make a point-based position look different from a pixel-based estimate. For example, the number 100 in Left does not mean 100 screen pixels. It is usually better to choose a location by running the form on the target setup than to convert coordinates using a guessed scaling factor.
Multi-monitor arrangements add another complication. Windows treats displays as a desktop arrangement, and secondary monitors can be placed to the left of, above, or below the primary display. A form positioned using fixed coordinates that looked appropriate on one computer may be misplaced on another, especially when display scaling differs. A centering mode is often more portable than hard-coded coordinates. If a form must open on a particular display, test it with the actual monitor arrangement and Excel window placement used by its audience; simple fixed coordinates do not identify a monitor by name.
Common positioning problems
- The form still opens in the wrong place: check that
StartUpPositionis Manual before assigningLeftandTop. Also confirm that the code is in the correct form’s module and that the form being shown is the one you edited. - The form appears partly off-screen: reduce the coordinates or use a centering option. This can happen after moving Excel between monitors or changing display settings.
- The form is centered on the wrong reference: distinguish screen centering from owner-window centering. If you need to center relative to Excel’s current window, calculate the coordinates from the Application properties.
- The location changes between computers: screen size, scaling, and monitor layout can differ. Avoid treating one set of numeric coordinates as universally suitable.
- The form is behind Excel or difficult to locate: examine how it is shown and whether Excel is active. Positioning controls location, not every aspect of window focus or stacking order.
When debugging, inspect the form’s Width and Height as well as its Left and Top values. A correctly calculated top-left coordinate can still place part of a large form beyond the available display area. A practical test is to open the form with Excel maximized and restored, and then repeat on any monitor arrangement that matters.
Design-time settings versus runtime placement
Design-time values are convenient when the form should always begin in the same place. They are visible in the Properties window and require no event code. Runtime placement is more adaptable: it can respond to Excel’s current window size, choose a location based on the form’s dimensions, or apply different rules for different workflows.
Use one clear source of positioning logic. If the Properties window specifies one location but an Initialize event assigns another, the code’s runtime assignment determines the final Manual coordinates. If a different startup mode is selected, that mode can interfere with expectations. Keeping the startup mode and coordinate-setting code together makes the behavior easier to understand and maintain.
Excel for Mac and Excel for the web
The examples are intended for desktop Excel for Microsoft 365 on Windows. Excel for Mac supports VBA and UserForms, but its windowing environment and monitor behavior differ from Windows. Do not assume that a coordinate arrangement or centering result will look identical across operating systems; test the form on the Mac versions and display setups you need to support. Excel for the web does not run VBA macros or display VBA UserForms, so this approach requires desktop Excel.
Frequently Asked Questions
How do I center an Excel VBA UserForm on the screen?
Set the form’s StartUpPosition property to 2 - CenterScreen. If you need to calculate and control the position yourself, set it to 0 - Manual and assign Left and Top before showing the form.
How do I center a UserForm over the Excel window?
Try 1 - CenterOwner, or use Manual placement and calculate the form’s center from Excel’s Left, Top, Width, and Height properties. The code example above uses the latter method.
Are UserForm Left and Top measured in pixels?
No. The properties use points. Display scaling affects how point-based dimensions appear in pixels, so a numeric coordinate should not be interpreted as the same number of pixels.
Where should the positioning code go?
Put code that runs as the form is initialized in that UserForm’s code module, inside its UserForm_Initialize event. Set Manual mode before assigning Left and Top.
Can a UserForm open in the same place on every monitor?
Not reliably through fixed coordinates alone. Monitor arrangement and scaling vary, and a coordinate does not specify a display by name. Use a centering mode when portability matters, then test on the configurations you support.
Does this work in Excel for the web?
No. Excel for the web does not run VBA macros or UserForms. Use desktop Excel for Windows or Mac, taking the platform-specific display behavior into account.
Related
- Excel Text to Columns: Choosing a Number Delimiter
- Excel Text to Columns Shortcut: Windows and Mac
- Excel Text to Columns: Split Cells at Line Breaks Easily
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Find the Last Used Cell When Filters Are OnTo find the last used cell in Excel VBA while a filter is active, search the worksheet with…
- Excel VBA Print: How to Print Sheets and WorkbooksTo print from Excel VBA, call an object’s PrintOut method: for example, ThisWorkbook.Worksheets("Report").PrintOut sends the Report sheet to…
- Excel VBA MsgBox Examples: Buttons, Results, and Tips for MacrosExcel VBA’s MsgBox function displays a message and can return the button the user clicks. For example, use…
- Excel VBA: Find a Character Position in a String with InStrIn Excel VBA, use InStr to find where a character or text fragment first appears in a string:…
- VBA Range Is Nothing? Meaning, Checks, and Common FixesIn Excel VBA, a Range is Nothing when an object variable does not currently refer to a range…
- Excel Analysis ToolPak vs ToolPak VBA: Key DifferencesExcel’s Analysis ToolPak is the add-in for running built-in statistical and engineering analyses from the Data tab; Analysis…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.