Excel VBA Frame With Scroll Bar: Setup and Code

VBA & macros · Updated November 3, 2026

Excel VBA Frame With Scroll Bar: Setup and Code

To make a scrollable area in Excel VBA, add a Frame to a UserForm, set its ScrollBars property to fmScrollBarsVertical or fmScrollBarsBoth, and make its ScrollHeight or ScrollWidth larger than the visible area. Put the controls inside the frame; a separate ScrollBar control is only needed when you want a slider to control something specific.

What a scrollable frame does

A UserForm frame is a container: it groups controls such as labels, text boxes, and command buttons. When its content takes up more space than the frame can display, scrollbars let the user move through that content without enlarging the form. This is useful for long questionnaires, settings panels, or lists of fields that need to stay together.

The distinction between a frame and a scrollbar matters. The frame can have its own scrollbars through its ScrollBars property. A standalone ScrollBar control is a different control, with its own minimum, maximum, and value; it does not automatically make other controls scroll. To use one as a custom controller, VBA must connect its value to a relevant action or property.

This article focuses on a Microsoft Excel for Microsoft 365 UserForm on Windows. A frame on a UserForm is not the same thing as a worksheet cell area, and inserting a scrollbar on a worksheet does not make a UserForm frame scroll.

Add a frame to a UserForm

  1. Open the Visual Basic Editor from Excel with Developer > Visual Basic. On Windows, Alt+F11 is a common shortcut; on some Mac keyboards, use Option+F11 or the Fn key as well.
  2. In the editor, choose Insert > UserForm if the project does not already contain one.
  3. Open the Toolbox if it is not visible, select Frame, and draw the frame on the form.
  4. Select the frame and use the Properties window to set its (Name), for example fraContent. Add the labels, text boxes, or other controls inside the frame, not merely on top of it.
  5. Set ScrollBars to 2 - fmScrollBarsVertical for vertical movement, or 3 - fmScrollBarsBoth if content extends in both directions. The numeric values correspond to the MSForms constants.

In the form designer, a control that appears visually within the frame may still belong to the form itself if it was drawn outside the frame. Check its parent/container relationship by moving the frame in the designer: controls that belong to it move with it. Cut and paste a control into the selected frame if necessary.

Set the scroll range and visibility

Choosing a scrollbar direction does not tell the frame how much content exists. Set ScrollHeight for vertical content and ScrollWidth for horizontal content. These dimensions use points, as do many UserForm layout measurements. Set the scroll dimension beyond the visible interior of the frame so there is actually an off-screen region to reveal.

For example, a frame that is about 250 points tall might need a ScrollHeight of 600 points if its controls extend that far. These are illustrative dimensions, not a universal setting: the right value depends on the frame size and where the lowest control ends. Leave a small margin below the last control so it is not crowded against the end of the scroll range.

The KeepScrollBarsVisible property determines whether the selected scrollbars remain visible when the full range may fit. If you prefer a scrollbar to appear only when needed, use fmScrollBarsNone for that property. In many layouts, leaving the scrollbar visible makes the presence of more content clearer. Avoid using visibility as a substitute for setting the correct scroll range.

Set the frame properties in VBA

You can configure the frame in the Properties window or in the form’s initialization event. The following example assumes a UserForm contains a frame named fraContent. Its sample height is deliberately fixed; adjust it to the actual content, or set the property in the designer instead.

Private Sub UserForm_Initialize()
    ' Configure the frame when the form opens.
    With Me.fraContent
        .ScrollBars = fmScrollBarsVertical
        .KeepScrollBarsVisible = fmScrollBarsVertical
        .ScrollHeight = 600
        .ScrollTop = 0
    End With
End Sub

Place this event procedure in the code module for the UserForm, not in a worksheet module or a standard module. In the VBA editor, select the form, open its code window, and choose UserForm and Initialize from the procedure drop-downs to create the event. The constant fmScrollBarsVertical is part of the Microsoft Forms control library available to UserForms. If you prefer the Properties window, set the same options there and omit the event code.

To start the form at a particular position, change ScrollTop for vertical scrolling or use ScrollLeft for horizontal scrolling. Normally, resetting the position to zero when the form opens is predictable. If users can reopen the form and expect it to remember where they were, preserve the position deliberately rather than resetting it every time.

Size the scroll area for real content

A reliable scroll range should cover the controls that actually belong to the frame. For vertical scrolling, inspect the bottom edge of the lowest control and add a little room; for horizontal scrolling, inspect the right edge of the furthest control. If controls are created or repositioned in code, update the scroll dimensions after laying them out. A hard-coded range can become incorrect when the form is resized or the content changes.

For a long form with repeated rows, consider whether a scrolling frame is the right design before adding dozens of controls. A compact set of fields, clear section labels, and a scrollbar can work well. But an extremely long or frequently changing list may be easier to manage in a worksheet, a list-oriented control, or several shorter pages. A frame’s scrollbar moves its contained content; it does not add a search feature, sort rows, or automatically create new controls.

Horizontal scrolling is possible, but it can make forms harder to use because users may lose sight of the context for a field. If the form needs both directions, group related information carefully and consider whether widening the form or reorganizing the controls would be clearer. Use two-way scrolling only when the extra width is genuinely necessary.

Frame scrollbars versus a separate ScrollBar control

Use the frame’s built-in scrollbars when the goal is to expose controls that extend beyond the frame’s visible area. The frame handles movement of its contents, so no event procedure is required just to scroll. This is usually the simplest choice for a long group of UserForm fields.

Use a standalone ScrollBar when the user should adjust a value, such as choosing a quantity or navigating a custom range. Set its properties such as Min, Max, and SmallChange to suit the task, then respond to its change event in VBA. It will not scroll a group of controls just because it is placed beside them; custom behavior needs code.

On a worksheet, Excel also offers scrollbar controls through the Developer tab’s control tools. A worksheet scrollbar can be linked to a cell or handled through its events, depending on the control type. That is a worksheet interface, not a scrollable UserForm frame. ActiveX controls on worksheets are Windows-specific and are not supported in Excel for Mac; do not assume a workbook using them will behave the same on Mac or Excel for the web.

Common problems and practical fixes

  • The scrollbar appears but cannot move. Increase ScrollHeight or ScrollWidth so the scroll range is larger than the visible area. Confirm that the intended dimension matches the scrollbar direction.
  • The controls do not move with the frame. They may be siblings on the form rather than children of the frame. Reparent them by cutting and pasting into the selected frame in the designer, then check that moving the frame also moves those controls.
  • The bottom fields are cut off. Increase the scroll dimension enough to include the bottom edge of the last control and a margin. Also check whether a control extends beyond the frame’s interior or is positioned outside it.
  • The scrollbar is missing until the form is resized. Review ScrollBars, KeepScrollBarsVisible, and the scroll dimensions. A scrollbar may not be needed if the full content fits, depending on the visibility setting.
  • The code reports that a control cannot be found. Confirm the frame’s (Name) property is exactly fraContent and that the procedure is in that UserForm’s module. The caption shown on the frame is not its VBA name.
  • The macro does not run. Save the workbook as a macro-enabled .xlsm file and use an appropriate macro security setting for a trusted workbook. Excel for the web cannot run VBA macros; open the file in desktop Excel.

Before running a macro that changes a workbook, save a separate copy. VBA actions cannot be undone with Ctrl+Z, so a backup is the dependable way to recover from an unwanted change. On Mac, the undo shortcut differs, but that does not make VBA operations undoable.

Compatibility and design choices

UserForms are VBA interfaces in desktop Excel, and their precise control behavior can depend on the Office and operating-system environment. Excel for Mac supports VBA, but the editor and available control behavior can differ from Windows; test a form on the platforms where it will be used. Excel for the web does not run VBA, so a UserForm-based workflow requires desktop Excel.

For users who need a simple on-sheet input, data validation lists, worksheet buttons, or a carefully designed input area may be easier to distribute than a VBA form. If the task is to display a large data set, a worksheet table with filters is often more appropriate than placing many fields in a scrolling frame. Choose a frame when the interaction is genuinely form-like and the controls form one coherent group.

Frequently Asked Questions

Can an Excel VBA frame have its own scrollbar?
Yes. A UserForm Frame has a ScrollBars property. Set it to vertical, horizontal, or both, and set the corresponding scroll dimension large enough to extend beyond the visible frame area.

Why does my frame scrollbar not scroll the controls?
Usually, the controls are not actually contained by the frame, or the frame’s ScrollHeight or ScrollWidth does not exceed its visible area. Check the controls’ parent relationship and the dimension for the direction you want to scroll.

Can I use a scrollbar on an Excel worksheet to scroll a UserForm?
Not automatically. A worksheet scrollbar and a UserForm frame scrollbar are separate controls. Connecting a worksheet control to a form would require a deliberate VBA design, and worksheet ActiveX controls are not available on Mac.

Can I make the scrollbar always visible?
Set the frame’s KeepScrollBarsVisible property to the desired scrollbar direction, such as fmScrollBarsVertical. The frame still needs an appropriate ScrollHeight or ScrollWidth for useful movement.

Will a VBA UserForm work in Excel for the web?
No. Excel for the web does not execute VBA macros or display VBA UserForms. Use desktop Excel for this interface, or redesign the workflow using features available in the web app.

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.