To show a horizontal scrollbar in a VBA ListBox, set the ScrollBars property to fmScrollBarsHorizontal (or fmScrollBarsBoth) in the Properties window or via code. By default, a ListBox only shows a vertical scrollbar when items exceed its height; horizontal scrolling must be explicitly enabled, and it only appears when content is wider than the control.
Why a Horizontal Scrollbar Is Hidden by Default
In Microsoft Forms (the VBA userform framework), the ListBox control has a ScrollBars property that accepts three relevant values: fmScrollBarsNone (0), fmScrollBarsHorizontal (1), fmScrollBarsVertical (2), and fmScrollBarsBoth (3). The default is fmScrollBarsVertical. This means the control automatically adds a vertical scrollbar when the list exceeds the visible height, but it never adds a horizontal one unless you change the property.
Even after setting ScrollBars to horizontal or both, the scrollbar will not appear if every item fits within the control’s width. The scrollbar only becomes visible when the widest item (or the sum of column widths, if using multi-column) exceeds the ListBox’s Width property. This is a common point of confusion: users set the property and see nothing, assuming it didn’t work.
How to Enable It: Design-Time and Run-Time
You can set the property in two ways:
- Design time (Properties window): In the VBA editor, select the ListBox on your UserForm. In the Properties window, find
ScrollBarsand choose1 - fmScrollBarsHorizontalor3 - fmScrollBarsBoth. This is the simplest method and works immediately. - Run time (VBA code): In the UserForm’s
Initializeevent or any procedure, set the property directly:
Private Sub UserForm_Initialize()
' Assume the ListBox is named ListBox1
Me.ListBox1.ScrollBars = fmScrollBarsHorizontal ' or fmScrollBarsBoth
End Sub
If you use fmScrollBarsHorizontal, the vertical scrollbar is disabled. If you need both, use fmScrollBarsBoth. Note that if the list has more items than fit vertically and you set only horizontal, users will not be able to scroll down—so choose fmScrollBarsBoth unless you are certain the list is short.
Making the Horizontal Scrollbar Actually Appear
Setting the property alone is not enough. The scrollbar appears only when the content exceeds the control’s width. For a single-column ListBox, the width is determined by the longest string in the list. For a multi-column ListBox (where ColumnCount is greater than 1), the total width is the sum of the ColumnWidths property, which you set as a semicolon-separated list (e.g., "60;100;80").
If the ListBox is too narrow, you have two options: widen the control or keep the width and let the scrollbar handle overflow. For example, if you have a ListBox with Width = 100 and items like “Supercalifragilisticexpialidocious”, the horizontal scrollbar will appear because the text is wider than 100 pixels. If your items are short but you still want a scrollbar (e.g., to force a consistent layout), you can set ColumnWidths to values that sum to more than the control’s width—this creates an overflow even with short text.
Common Problems and Misconceptions
- Scrollbar doesn’t show even after setting property: As noted, the content must be wider than the control. Check the actual pixel width of the longest item. Also, if you set
ScrollBarstofmScrollBarsHorizontalbut the list has many items, the vertical scrollbar disappears, which might look like the control is broken. - Multi-column ListBox with
ColumnWidthsnot set: If you don’t setColumnWidths, the control auto-sizes columns to the longest item in each column, which may or may not exceed the total width. Set explicit widths to guarantee overflow. - Using
ListIndexorListproperty doesn’t affect scrollbar visibility: The scrollbar is purely visual; it does not change how you add or retrieve items. - Scrollbar appears but is grayed out: This happens when the content fits exactly or when the control has
Enabled= False. Ensure the control is enabled.
Alternatives: When Not to Use a Horizontal Scrollbar
Horizontal scrollbars in a ListBox can be awkward because users often don’t realize they can scroll sideways. Consider these alternatives:
- Widen the ListBox: If the form layout allows, increase the
Widthproperty so all content fits. This is the most user-friendly solution. - Use
ColumnWidthsto truncate and add ellipsis: The ListBox does not natively support ellipsis, but you can setColumnWidthsto a fixed width and manually truncate strings in your code (e.g.,Left(text, 20) & "..."). This avoids scrolling altogether. - Use a ListView control (MSComctlLib): The ListView in the Microsoft Windows Common Controls has a
Viewproperty that supports horizontal scrolling more naturally, but it requires an additional reference and is more complex. - Use a ComboBox: If the user only needs to select one item, a ComboBox with a dropdown list is often a better choice; it scrolls horizontally in the dropdown automatically when needed.
Cost and Compatibility
There is no cost associated with the ScrollBars property—it is a built-in feature of the ListBox control in VBA for Microsoft Office (Excel, Word, Access, etc.). The property works in all modern versions of Office on Windows. On a Mac, VBA support is limited; the ListBox control exists but the behavior may differ slightly, and the horizontal scrollbar may not render in the same way. If you are developing for Mac, test thoroughly.
Frequently Asked Questions
Why does my horizontal scrollbar not appear even though I set ScrollBars to fmScrollBarsBoth?
Because the content width does not exceed the control’s width. Check the longest item’s pixel width. For a multi-column ListBox, ensure the sum of ColumnWidths is greater than the ListBox’s Width. If not, the scrollbar stays hidden.
Can I force a horizontal scrollbar to always show?
No, the ListBox does not have a property to force the scrollbar to be permanently visible. It only appears when content overflows. To simulate a permanent scrollbar, you could add a dummy column with a large width, but that is a hack and not recommended.
How do I set ColumnWidths for a multi-column ListBox?
In the Properties window, set ColumnCount to the number of columns, then set ColumnWidths as a string like "50;80;120" (semicolons separate widths in points, not pixels). In code, use ListBox1.ColumnWidths = "50;80;120".
Does the horizontal scrollbar work with the List property when adding items?
Yes. The scrollbar is purely visual and depends on the rendered width of the items. Adding items via AddItem or the List property works the same; the scrollbar appears if any item is wider than the control.
My ListBox is in a multi-column layout and the horizontal scrollbar is missing—what am I doing wrong?
You likely haven’t set ColumnWidths. Without it, the ListBox auto-fits columns to content, which may not exceed the control width. Set explicit widths that sum to more than the control’s width, and set ScrollBars to fmScrollBarsBoth.
Is there a way to scroll horizontally with the mouse wheel?
No, the ListBox does not support horizontal mouse wheel scrolling natively. Users must drag the scrollbar or use Shift+Mouse Wheel in some Office versions, but that is not guaranteed. Consider widening the control to avoid the need.
Code Example: Adding Items and Enabling Both Scrollbars
Private Sub UserForm_Initialize()
' Save a copy of the workbook before running any macro
' that modifies the userform or workbook.
' Enable both scrollbars
Me.ListBox1.ScrollBars = fmScrollBarsBoth
' Set column widths (if multi-column)
Me.ListBox1.ColumnCount = 2
Me.ListBox1.ColumnWidths = "80;120" ' total 200 points
' Add some long items to demonstrate horizontal scrolling
Me.ListBox1.AddItem "Short"
Me.ListBox1.List(0, 1) = "This is a very long second column text that will overflow the width"
Me.ListBox1.AddItem "Another"
Me.ListBox1.List(1, 1) = "More long text here to ensure overflow"
End Sub
Remember to always save a copy of your workbook before running any macro, as macros cannot be undone with Ctrl+Z.
Related
- Shortcut to Switch Off Computer: Fastest Ways
- Generate Random Number in Unity: C# Script Guide
- Free Data Entry Software for Windows 10: 7 Real Options
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA InputBox Example: Get and Validate User InputA VBA InputBox example can ask for a value, store the reply, and use it in a macro.…
- Excel VBA Array Append: Safe Methods and ExamplesTo append a value to a one-dimensional Excel VBA array, increase its upper bound with ReDim Preserve, then…
- VBA Delete Whole Row: Safe Methods and ExamplesTo delete an entire worksheet row with VBA, use Rows(5).EntireRow.Delete, replacing 5 with the row number you want…
- Excel VBA Error Messages: Causes, Codes, and FixesAn Excel VBA error message means the macro could not compile, run an instruction, or complete an operation…
- VBA For Next Loop: Syntax, Examples, and Common ErrorsA VBA For...Next loop repeats a block of code for a counter that moves through a specified range.…
- Excel VBA Import From Another Workbook: A Safe GuideTo import a worksheet with VBA, open the source workbook, copy the required worksheet into the workbook containing…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.