To position a VBA UserForm, set its StartUpPosition property to 1 - CenterOwner or 2 - CenterScreen for automatic placement. For a specific location, choose 0 - Manual and set the form’s Left and Top properties before it appears.
How UserForm positioning works
A UserForm has properties that determine where it opens and how it is sized. In the Visual Basic Editor (VBE), select the form in Project Explorer, open its Properties window, and find StartUpPosition. The property offers four choices:
0 - Manual: use the form’sLeftandTopvalues to specify its position.1 - CenterOwner: center the form over its owner, typically the Excel window that opened it.2 - CenterScreen: center the form on the screen.3 - Windows Default: let Windows choose the position.
The Left and Top properties are measured in points, not pixels. They describe the form’s position: Left is the horizontal coordinate and Top is the vertical coordinate. A larger Left moves the form to the right; a larger Top moves it down. The form’s Width and Height also use points, so they can be used directly in positioning calculations.
For a simple dialog, centering is usually preferable to hard-coding coordinates. Coordinates depend on window size, display setup, and scaling, while the built-in options require little maintenance.
Choosing the right positioning method
Pick the method based on what the form is for, rather than choosing manual coordinates by default. A confirmation or data-entry dialog usually belongs near the workbook window that launched it. A welcome screen or standalone utility may be more appropriate in the center of the screen.
- Use CenterOwner when users need to relate the dialog to the active Excel window. It is a practical default for modal prompts.
- Use CenterScreen when the form should be prominent and independent of the workbook’s location.
- Use Manual when the form must align with a particular window edge, open at a saved location, or follow a layout rule.
- Use Windows Default only when the operating system’s placement is acceptable. It gives you less control over where the form appears.
These settings choose the form’s initial location; they do not make it permanently attached to Excel or keep it centered if the user moves the workbook afterward. If a form is modeless, the user can interact with Excel while the form remains open, so a location that avoids covering important cells can be especially useful.
Center a form in Excel with manual coordinates
For more control than the built-in centering options provide, use manual placement. The following example centers a form within the Excel application window. Put the code in the form’s code module, replacing frmNotice in your launch code with the actual form name as needed. Set StartUpPosition to Manual in the Properties window, or set it in the event code as shown.
Private Sub UserForm_Initialize()
Dim excelLeft As Double
Dim excelTop As Double
Dim excelWidth As Double
Dim excelHeight As Double
' Read the Excel window position and size in points.
excelLeft = Application.Left
excelTop = Application.Top
excelWidth = Application.Width
excelHeight = Application.Height
' Use manual placement and center the form over Excel.
Me.StartUpPosition = 0
Me.Left = excelLeft + (excelWidth - Me.Width) / 2
Me.Top = excelTop + (excelHeight - Me.Height) / 2
End Sub
For example, if Excel is 900 points wide and the form is 300 points wide, the horizontal inset is 300 points: half of the 600-point difference. The same calculation applies vertically. Because the values are all in points, there is no need to convert the form dimensions to pixels.
This calculation centers within the Excel window’s reported bounds, not necessarily within the usable portion of a monitor. If the form is larger than the Excel window, the calculation can produce a negative offset relative to that window. A form can then be partly off-screen, so check the result with the actual form size and typical Excel window arrangement. For ordinary dialogs, CenterOwner avoids maintaining this calculation.
When to set the position
Set the form’s location before it is displayed. The UserForm_Initialize event is a convenient place because it runs when the form is loaded and before it is shown. It is also suitable for setting up controls or loading initial values. A typical call to display a default form instance is frmNotice.Show.
For predictable behavior, avoid showing the form first and moving it afterward. That can make the form visibly jump, and it may briefly appear at the default location. If the position depends on information that is only available later, calculate it before the call to .Show, or update the position while the form is still hidden.
If you use a form instance created with New, set properties on that same instance before showing it. A setting applied to a different instance will not affect the one the user sees. This distinction matters in projects that create multiple forms or repeatedly unload and recreate a form.
Positioning on multiple monitors and at different display scales
A form centered on a screen may not appear on the monitor a user expects when a computer has more than one display. The active Excel window’s location, Windows display arrangement, and the Office version can affect the result. Test the chosen setting with Excel on each monitor that matters to your users, especially if they move the workbook between displays.
Display scaling is another reason to prefer the built-in centering settings when exact coordinates are not essential. VBA form dimensions and position properties use points, while screen measurements and Windows APIs may use other units. A hard-coded pixel value or a conversion copied from another environment can therefore place the form incorrectly on a high-DPI display.
If you must use manual placement, base the calculation on the current window dimensions rather than a fixed number such as Left = 200. Fixed coordinates can look reasonable on one screen and put the form near an edge or outside the visible area on another. For applications that must account precisely for monitor work areas, Windows API code may be required; that introduces extra complexity and should be tested separately for 32-bit and 64-bit Office.
Common positioning problems and fixes
- The form still opens in the wrong place: Check that
StartUpPositionis set to the intended value and that code is changing the same form instance that is displayed. For manual placement, setLeftandTopbefore showing the form. - The form appears off-screen: A saved or calculated coordinate may no longer suit the current monitor arrangement. Try
CenterOwnerorCenterScreen, then reopen Excel and test on the user’s usual display setup. - The form is centered over the wrong window: Check whether the workbook or Excel window is on another monitor, and compare the result with
CenterScreen. These options have different purposes: one relates to the owner, the other to the screen. - The form jumps after opening: The position is probably being changed after it becomes visible. Move the calculation to initialization or set the coordinates before calling
.Show. - Manual values do not match pixel measurements: Remember that
Left,Top,Width, andHeightare in points. Do not treat a point as a screen pixel.
Also distinguish a form’s initial position from its size. Changing Left and Top moves it; changing Width and Height resizes it. If a form is too large to fit, repositioning alone will not make all its controls visible.
Windows, Mac, and Excel for the web
This guidance is for Excel for Microsoft 365 on Windows. The UserForm properties and basic VBA approach are also relevant to desktop Excel for Mac, but display behavior, available system-level techniques, and keyboard shortcuts can differ. If the built-in positioning options meet the requirement, they are generally a simpler cross-platform choice than Windows-specific API calls.
On Windows, Alt+F11 opens the Visual Basic Editor from Excel. On a Mac, the usual shortcut is Option+F11; depending on the keyboard, you may also need to hold Fn. You can use Excel’s Developer tab to open Visual Basic instead. Excel for the web does not run VBA macros or display VBA UserForms, so users need desktop Excel to use this kind of interface.
Before running a macro that changes a workbook, save a copy. Macro actions cannot be undone with Ctrl+Z in Windows Excel; on Mac, Command+Z likewise does not reverse VBA changes.
Frequently Asked Questions
How do I center a VBA UserForm on the screen?
Set the form’s StartUpPosition property to 2 - CenterScreen in the Properties window. You can also assign Me.StartUpPosition = 2 in the form’s initialization code.
What is the difference between CenterOwner and CenterScreen?CenterOwner places the form in relation to its owner, usually Excel. CenterScreen centers it on the screen. Choose based on whether the dialog should follow the workbook window or be positioned independently.
How can I set an exact UserForm position?
Set StartUpPosition to 0 - Manual, then assign numeric values to the form’s Left and Top properties before it is shown. The values are in points.
Why does my UserForm open partly off-screen?
Its manual coordinates may be based on a different window size, monitor layout, or display scale. Try a built-in centering option, or recalculate its location from the current Excel window dimensions.
Can a VBA UserForm run in Excel for the web?
No. Excel for the web does not run VBA macros or VBA UserForms. Open the workbook in desktop Excel to use the form.
Related
- Microsoft Excel Corrupt File? How to Repair It
- Microsoft Excel Find Circular References: A Clear Guide
- Microsoft Excel Consolidate Data: A Practical Guide
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: Check Whether a Worksheet ExistsTo check whether a worksheet exists in Excel VBA, loop through the target workbook’s Worksheets collection and compare…
- VBA Find Last Column With Data: Reliable VBA MethodsTo find the last column containing a value or formula anywhere on a worksheet, use VBA’s Range.Find method…
- VBA Find the Next Empty Row in Excel AutomaticallyTo find the next row for appending data in VBA, use Cells(Rows.Count, "A").End(xlUp).Row + 1, replacing column A…
- Excel VBA Find Numbers Only: Code, Search Tips, and FixesYes. To find cells that contain real numeric values—not numbers stored as text—loop through the range and check…
- Excel VBA: Keep a UserForm on TopTo keep an Excel VBA UserForm above other windows on Windows, call the Windows API function SetWindowPos with…
- VBA Dictionary Methods: Add, Exists, Keys and MoreA VBA Dictionary stores pairs of unique keys and associated values, and its core methods are Add, Exists,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.