In Excel VBA, a scrollbar can mean a worksheet navigation bar, a scroll bar control linked to a cell, or a control used in a VBA UserForm. For an interactive worksheet input, add a Scroll Bar from Developer > Insert, set its value range and cell link, then use VBA only if you need custom behavior; the built-in worksheet scrollbars simply move around the sheet.
What a scrollbar does in Excel
The word “scrollbar” covers two different jobs. The familiar bars at the bottom and right edge of a worksheet move the visible window through columns and rows. They do not represent a value for a calculation. A scroll bar control, by contrast, is an interactive object whose position corresponds to a number. You can use that number to select an item, adjust a setting, or update a display.
For example, a dashboard might use a control with values from 1 to 12 to choose a month. A linked cell then holds the selected number, and formulas or VBA can use it to show the relevant data. The user drags the thumb, clicks an arrow, or clicks the track to change the value. The size and direction of the change depend on the control’s settings.
VBA is optional for simple inputs. A Forms control can write its value to a linked cell without any code. VBA becomes useful when changing the scrollbar should update other cells, select a record, or trigger a more involved action.
Choose the right kind of scrollbar
Excel offers several things that can look or sound similar. Choose based on whether the user is navigating the sheet or entering a value, and whether you need VBA events.
- Worksheet navigation bars: These are part of Excel’s window, not objects placed on the worksheet. They scroll the visible grid.
- Forms control Scroll Bar: This is a worksheet object with a numeric value and a linked cell. It is usually the simplest option for a dashboard or worksheet input.
- ActiveX ScrollBar: This worksheet control exposes properties and events to VBA, making it suitable for custom interactions. It requires more setup and is not supported in Excel for Mac.
- UserForm ScrollBar: This is a control in a VBA form. It can change a value inside the form or drive other form controls through code.
Do not confuse a scroll bar control with a Spin Button. Both can change a number, but a Spin Button uses up and down arrows rather than a draggable thumb. If users need to move quickly across a wide range, a scrollbar can be easier to operate; if they need precise, small increments, a Spin Button or a text box may be clearer.
Add a Forms control to a worksheet
In Excel for Microsoft 365 on Windows, show the Developer tab if it is missing: select File > Options > Customize Ribbon, check Developer, and select OK. Then follow these steps:
- Open Developer > Insert and, under Form Controls, select Scroll Bar.
- Drag on the worksheet to draw the control. Right-click it and choose Format Control.
- On the Control tab, set the minimum and maximum values, the incremental change, and the page change.
- Enter a cell in the Cell link box, such as B2, and select OK.
- Test the arrows, track, and thumb. The linked cell should change as you operate the control.
The minimum and maximum define the numeric limits. Incremental change controls the step when a user clicks an arrow or uses the keyboard. Page change controls the larger step associated with clicking the track. For a month selector, for instance, use a range of 1 through 12 and an increment of 1. A linked cell will then show the selected month number.
Keep the linked cell somewhere sensible: it can be visible, placed in a clearly labeled input area, or hidden on a support sheet. If you hide it, document its purpose so another person can maintain the workbook. The linked cell contains the control’s numeric value; it does not automatically turn 1 into January or perform any other interpretation.
Use an ActiveX scrollbar with VBA
An ActiveX ScrollBar is useful when you want a VBA event to run as the value changes. In Windows Excel, choose Developer > Insert and select Scroll Bar under ActiveX Controls, then draw it on the sheet. Turn on Developer > Design Mode to select and configure it. Right-click the control and choose Properties to set values such as Min, Max, SmallChange, LargeChange, and Value. The control’s name, often ScrollBar1 initially, is also shown in the Properties window.
To add an event procedure, right-click the ActiveX control and choose View Code. Put the procedure in the worksheet’s code module, not in a standard module. This example writes the selected value to cell B2 whenever the control changes:
Private Sub ScrollBar1_Change()
Dim selectedValue As Long
' Read the control and display its value in B2.
selectedValue = Me.ScrollBar1.Value
Me.Cells(2, 2).Value = selectedValue
End Sub
Return to the worksheet and turn off Design Mode to operate the control. While Design Mode is on, clicks select or edit the control rather than use it. The event procedure assumes the ActiveX control is named ScrollBar1 and belongs to the same worksheet module. If you rename the control, update the procedure name and reference accordingly.
Save a copy of the workbook before running or changing VBA. Macros cannot be undone with Ctrl+Z, so retain a backup if a macro may change workbook contents. Save a workbook containing VBA as an Excel Macro-Enabled Workbook (.xlsm), and use an appropriate trusted location or security settings for macros.
Scrollbars in VBA UserForms
A UserForm is a custom dialog built in the Visual Basic Editor. To add a ScrollBar control, open the form in the editor, show the Toolbox, and select the ScrollBar tool. Set properties such as Min, Max, SmallChange, LargeChange, and Value in the Properties window. You can then respond to its Change event in the form’s code module.
A form-level scrollbar is different from a scrollbar used to scroll the contents of a form. If controls extend beyond the visible form area, the form’s scrolling properties—such as ScrollHeight, ScrollWidth, and ScrollBars—can define a scrollable region. A standalone ScrollBar control, on the other hand, is an input that has a numeric value. Pick the first approach for navigating oversized form content and the second for changing a parameter.
For a form input, the Change event can copy the control’s value to a label or use it to update a preview. Keep the allowed range and displayed meaning obvious: a control that shows 1 to 100 is less useful if users cannot tell whether 1 means the oldest record, the lowest zoom, or something else.
Adjust worksheet navigation separately
If the usual horizontal or vertical worksheet bar is missing, adding a VBA ScrollBar control will not restore it. In Windows Excel, check File > Options > Advanced. Under Display options for this workbook, enable Show horizontal scroll bar or Show vertical scroll bar as needed. The setting applies to the selected workbook. Also check whether the window is maximized or whether the sheet tabs and horizontal bar share limited space at the bottom of the window.
Excel can also restrict the cells a user may select with a worksheet’s ScrollArea property, but that is not a visual scrollbar and does not create a control. Similarly, hiding rows or columns changes what appears on the sheet; it does not change the numeric range of a Scroll Bar control. These distinctions help avoid trying to solve a navigation problem with an input control.
Common problems and fixes
- The control moves but the linked cell does not update: For a Forms control, reopen Format Control and check the Cell link. Confirm the referenced cell is on the intended sheet and is not protected against editing.
- The value stops at an unexpected number: Check Min and Max. The control cannot move outside that range. Also confirm that a VBA event or another macro is not resetting the value.
- The ActiveX control cannot be clicked: Turn off Developer > Design Mode. If it still does not respond, check whether the sheet is protected or whether Excel has disabled ActiveX controls under its security settings.
- VBA reports that a control or event name is missing: Verify the control’s name in the Properties window and place the event procedure in the correct worksheet or UserForm module. The event procedure name must match the control name.
- The control works on one computer but not another: ActiveX controls are not supported in Excel for Mac, and they do not run as VBA controls in Excel for the web. For a workbook shared across platforms, consider a Forms control or a cell-based input instead, and check the target versions before relying on control behavior.
Excel for the web cannot run VBA macros. Mac Excel supports VBA in general, but it does not support ActiveX controls; availability and behavior of worksheet Forms controls can also vary by version. If the workbook must be used on Windows, Mac, and the web, test the actual workflow on each platform rather than assuming a Windows control will behave identically everywhere.
Alternatives and usability
A scrollbar is not always the best input. It can be hard to set an exact value when the range is large, and the thumb may be difficult to use for people who rely on a keyboard or assistive technology. Consider a drop-down list for a short set of named choices, a validated cell for direct numeric entry, or a Spin Button for small, repeated changes. A scrollbar is most helpful when the user is choosing from an ordered range and seeing the selection change immediately.
Label the control with its purpose and show the current selection in a nearby cell or text label. If a value such as 3 means March, display “March” as well as the underlying number where practical. For accessibility and reliability, provide another way to enter or identify the value, avoid relying on color alone, and keep the control’s range aligned with the available data.
Frequently Asked Questions
How do I add a scrollbar in Excel VBA?
For a worksheet input on Windows, choose Developer > Insert > Scroll Bar under Form Controls, draw it, and set its range and linked cell through Format Control. Choose an ActiveX ScrollBar instead if you need its VBA events.
How do I link a scrollbar to a cell?
Right-click a Forms control Scroll Bar, choose Format Control, open the Control tab, and enter the destination in Cell link. The cell displays the control’s current numeric value.
Why is my Excel scrollbar not working?
For an input control, check its range, cell link, sheet protection, and—if it is ActiveX—Design Mode and security settings. For a missing worksheet navigation bar, check the workbook’s display options in File > Options > Advanced.
Can I use an ActiveX scrollbar on a Mac?
No. Excel for Mac does not support ActiveX controls. If the workbook needs to work on Mac, use a compatible alternative such as a Forms control where available, a drop-down, or a validated cell, and verify the behavior in the target Excel version.
Can an Excel scrollbar select text such as a month name?
A scrollbar control itself provides a number, not a month name. Use that number as an index or have a formula or VBA translate it into a label, then display the label beside the control.
Related
- How to Name a Range in Excel: Step-by-Step Instructions
- Excel Name Manager Spill Range: Create and Use One
- Excel Edit Defined Name Range: Steps and Common Fixes
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA UserForm Design: Build a Practical Excel FormTo design a VBA UserForm in Excel, open the Visual Basic Editor, choose Insert > UserForm, add controls…
- Access VBA: Open an Excel File and Work With Its DataYes. Access VBA can open an Excel workbook by controlling the Excel application, or it can import worksheet…
- Excel VBA Documentation: Where to Find the Right HelpExcel VBA documentation is available from Microsoft Learn: use the Excel object model reference for Excel-specific objects and…
- Excel VBA: Check If AutoFilter Is Active on a SheetIn Excel VBA, check Worksheet.AutoFilterMode to find out whether AutoFilter arrows are displayed, and check Worksheet.FilterMode to find…
- Access VBA: How to Delete Table Rows Safely and CorrectlyIn Access VBA, a “row” is usually a record in a table. To delete matching records, run a…
- Dynamic Pivot Table VBA: Fixing Common Code FailuresYes—dynamic PivotTable VBA can fail, but the cause is usually a mismatch between the source data, the PivotCache,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.