To add a scrollbar to an Excel VBA UserForm, set its ScrollBars property to vertical, horizontal, or both, then set ScrollHeight or ScrollWidth large enough to cover the controls that extend beyond the visible area. In the Visual Basic Editor, you can do this in the Properties window or in VBA code; the key is that the scrollable area must be larger than the form’s visible interior.
What a UserForm scrollbar does
A UserForm scrollbar lets someone move through content that does not fit in the form’s current viewport. It does not enlarge the form or resize its controls. Instead, it shifts the visible portion of a larger scrollable area, much like scrolling a document inside a window. This is useful when a form has many fields, instructions, or options but needs to stay a manageable size on screen.
The form’s ScrollBars property determines which directions are available. Its main settings are fmScrollBarsNone, fmScrollBarsHorizontal, fmScrollBarsVertical, and fmScrollBarsBoth. The matching numeric values are 0, 1, 2, and 3. In most data-entry forms, vertical scrolling is the practical choice: users can move down through the fields while the form keeps a consistent width.
A form scrollbar is different from a ScrollBar control you add from the Toolbox. A ScrollBar control is an input that can change a value, such as a number or a setting. The UserForm’s own scrollbar navigates around content; it does not automatically change a data value or provide a meaningful selection by itself.
Choose the direction and scrolling area
Set the direction according to the layout. Choose vertical scrolling when the content is taller than the visible form, horizontal scrolling when it is wider, and both only when users genuinely need to move in both directions. Horizontal scrolling can make forms harder to use because labels and values may no longer be visible together. Before choosing it, consider shortening labels, wrapping text, or widening the form.
The scroll area is controlled by the form’s ScrollHeight and ScrollWidth properties. These describe the total content area available for scrolling, in points. A point is a measurement unit used by Office controls; it is not a screen pixel. The visible viewport is the interior space available after the form’s borders and any other interface elements are accounted for.
- For vertical scrolling, make
ScrollHeightgreater than the visible interior height. - For horizontal scrolling, make
ScrollWidthgreater than the visible interior width. - Position every control within the intended scrollable area. A large scroll dimension does not move controls into place for you.
- Leave enough space at the bottom or right edge for the last control to be reached comfortably.
For example, if a form’s visible interior is about 250 points tall and its lowest control ends around 450 points from the content origin, a ScrollHeight of 480 points gives the user room to reach it. The exact value depends on the actual form layout, so inspect the control positions rather than copying a number without checking.
Set the properties in the Visual Basic Editor
In Excel for Microsoft 365 on Windows, open the workbook in desktop Excel and press Alt+F11 to open the Visual Basic Editor. On a Mac, Option+F11 is the usual shortcut, though some keyboards require Fn as well. Excel for the web cannot run VBA UserForms. In the Project Explorer, open the relevant workbook and double-click the UserForm. If the Properties window is hidden, press F4 on Windows or use the View menu to show it.
- Select the blank area of the UserForm, not a textbox or another control.
- In the Properties window, set
ScrollBarsto2 - fmScrollBarsVerticalfor a vertical bar, or choose the direction that suits the form. - Set
ScrollHeightto the full height needed for the content. SetScrollWidthif horizontal scrolling is required. - Place the controls at their intended positions, including those below or to the right of the visible area.
- Run the form and check that users can reach the final control and that no essential label is obscured.
The KeepScrollBarsVisible property controls whether the selected bars remain visible even when scrolling is not currently needed. Its values use the same none, horizontal, vertical, and both choices. If you want a bar to appear only when the area needs scrolling, do not force it to remain visible. Keeping a bar visible can make the layout more predictable, but it also takes up a little screen space.
Set scrolling in VBA code
You can set the properties in the UserForm’s initialization event when the values should be applied every time the form opens. In the Project Explorer, open the form’s code window and add code to its UserForm_Initialize event. This example assumes that the controls have already been positioned within a content area about 480 points tall:
Private Sub UserForm_Initialize()
Dim contentHeight As Single
' Set the full height needed to reach the form controls.
contentHeight = 480
Me.ScrollBars = fmScrollBarsVertical
Me.KeepScrollBarsVisible = fmScrollBarsVertical
Me.ScrollHeight = contentHeight
Me.ScrollTop = 0
End Sub
ScrollTop sets the vertical position, and ScrollLeft sets the horizontal position. Setting ScrollTop to zero starts the form at the top when it opens. The KeepScrollBarsVisible line in this example asks for the vertical bar to remain visible; remove that line or use the appropriate setting if you prefer the bar to appear only when needed. The form’s scroll dimensions still need to be large enough for its content.
Save a copy of the workbook before running a macro. VBA actions cannot be undone with Ctrl+Z, even if the form itself is being used to enter or change workbook data. Save macro-enabled workbooks in a format such as .xlsm if you need to retain VBA code.
Use a Frame for a scrollable section
Sometimes the entire form should remain fixed while just one area scrolls. In that case, add a Frame control from the Toolbox, put the related controls inside it, and configure the Frame’s own scrollbar properties. Set the Frame’s ScrollBars direction and its ScrollHeight or ScrollWidth so the controls inside the Frame fit in its larger scroll area.
This arrangement is helpful when a form has a fixed title, buttons, or instructions that should stay visible while a long list of fields moves. For example, a form might keep its Save and Cancel buttons outside a scrolling Frame at the bottom. Users can scroll through the fields without losing access to those buttons. Make sure the controls intended to move are actually contained by the Frame; a control merely placed visually over the Frame may not behave as part of its contents.
If a form uses a MultiPage control, a Frame inside a page can provide a scrollable region for that page’s content. This keeps the navigation tabs fixed while the content area moves. A Frame is also a useful alternative when different sections need independent scrolling, though multiple scrollbars can make an interface confusing if the boundaries are not clear.
Common problems and how to fix them
- No scrollbar appears: Check that the form or Frame has the intended
ScrollBarssetting and thatScrollHeightorScrollWidthexceeds the visible area. Also check whether the bar is configured to stay hidden unless needed. - The bar appears, but the bottom control cannot be reached: Increase the corresponding scroll dimension and confirm the control’s position. The scroll area must extend far enough to include the control’s bottom or right edge.
- The bar is visible but does not move the content as expected: Confirm that the controls belong to the object being scrolled. For a Frame, controls must be contained within that Frame, not merely drawn on top of it.
- There is a large empty area: The scroll dimension may be much larger than the content. Reduce it to a value that still allows the last control to be reached, then test the form again.
- A horizontal bar appears unexpectedly: Check whether a control or the scroll width extends farther right than intended. Widen the form, reposition or resize the control, or correct
ScrollWidth. - The scrollbar covers part of a control: Leave a margin near the edge of the scroll area and check the layout at the form’s actual size. A bar uses part of the available viewport, so an edge-to-edge design may need adjustment.
Also distinguish a form’s scrollbar from scrollbars on individual controls. A textbox can have its own scrolling behavior for its text, while a UserForm scrollbar moves the form’s content area. If only a long note needs scrolling, a multiline textbox with its own scrollbar may be clearer than making the whole form scroll.
When to use a scrollbar or another layout
Scrolling is appropriate when the form needs more room than the available screen or when a long set of fields naturally reads from top to bottom. It is not always the best response to a crowded design. A wider form, shorter labels, grouped sections, or a MultiPage layout can reduce the amount users must scroll. A MultiPage control is useful when the fields divide into distinct tasks, such as Details, Preferences, and Review; users then switch sections rather than moving through one long panel.
Use a form scrollbar when users need to move through one continuous area. Use a Frame scrollbar when only one section should move and other controls must stay fixed. Use a ScrollBar control when the user should adjust a value, not navigate the form. For a short list of choices, a ComboBox or ListBox may be easier than presenting many separate controls. The goal is to make the content and the navigation understandable, not simply to fit every control onto one form.
Test the finished form at the size people will actually use. Check that the first and last fields are reachable, that buttons remain accessible, and that the scroll direction feels natural. If the workbook must run on both Windows and Mac, test it in both desktop versions: VBA and UserForm compatibility can differ, and Windows ActiveX controls are not supported in Excel for Mac in the same way. Neither desktop platform’s VBA UserForms run in Excel for the web.
Frequently Asked Questions
How do I add a vertical scrollbar to a VBA UserForm?
Set the UserForm’s ScrollBars property to fmScrollBarsVertical, then set ScrollHeight large enough to include the lowest control. Check that the control positions extend into that scrollable area.
Why is my UserForm scrollbar not showing?
The scroll area may not be larger than the visible interior, the scrollbar direction may be set to none, or the bar may be configured to appear only when needed. Check ScrollBars, KeepScrollBarsVisible, and the relevant scroll dimension.
What is the difference between ScrollBars and ScrollHeight?ScrollBars selects which directions the form can scroll. ScrollHeight sets the total vertical extent of its scrollable area, while ScrollWidth sets the horizontal extent. Both the direction and a sufficiently large area are needed for useful scrolling.
Can I keep buttons fixed while the fields scroll?
Yes. Put the fields inside a scrollable Frame and leave the buttons outside it on the UserForm. The Frame moves its own contents while the buttons remain in place.
Does a UserForm scrollbar work in Excel for the web?
No. Excel for the web does not run VBA macros or VBA UserForms. Use desktop Excel to run the form, and test separately on Mac if the workbook is intended for Mac users.
Related
- Hide a Column in Power BI: Table Visuals and Models
- Conditional Formatting Greater Than: Excel Rules Explained
- Scatter Plot Data Sheet: How to Set Up and Read One
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Pivot Table Update: Refresh Tables and ReportsTo update a PivotTable with VBA, call its RefreshTable method; to refresh every PivotTable and external data range…
- Add Controls to a VBA UserForm: Steps and CodeTo add controls to a VBA UserForm, open the form in the Visual Basic Editor and drag a…
- Copy-Paste VBA Code: Add, Run, and Troubleshoot ItTo copy and paste VBA code into Excel for Microsoft 365 on Windows, press Alt+F11 to open the…
- Scrollbar in Excel VBA: Forms, Controls, and CodeIn Excel VBA, a scrollbar can mean a worksheet navigation bar, a scroll bar control linked to a…
- Create a Pivot Table in Excel Using VBATo create a PivotTable with VBA, prepare a rectangular data range with clear headers, then use a PivotCache…
- Convert an Excel Range to HTML in VBATo convert a range to a formatted HTML file in Excel for Microsoft 365 on Windows, add a…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.