Get our FREE VBA eBook of the 30 most useful Excel VBA macros.

Automate Excel so that you can save time and stop doing the jobs a trained monkey could do.

Claim your free eBook

Manipulating and changing scroll bars with VBA

VBA Code Snippets

When recording a macro, Excel includes all the scroll bar movement in the code.  Normally, we delete this code, as we just don’t need it.  But occasionally, being able to control the scroll bars and their display properties is useful.

Display or Hide Scroll Bars

Scroll bars can be displayed or hidden.  It is an application level setting, so will be applied to all workbooks open within the application.

The code below shows how to hide or display the scroll bars for all workbooks open in the application.

'Display all Scroll Bars
Application.DisplayScrollBars = True
'Hide all Scroll Bars
Application.DisplayScrollBars = False

The below shows how to hide or display either the horizontal or vertical scroll bars for active workbook.

'Hide all the vertical or horizontal Scroll Bar
ActiveWindow.DisplayHorizontalScrollBar = False
ActiveWindow.DisplayVerticalScrollBar = False
'Display the vertical or horizontal Scroll Bar
ActiveWindow.DisplayHorizontalScrollBar = True
ActiveWindow.DisplayVerticalScrollBar = True

Fix the Scroll Area

Fixing the scroll area will prevent a user from scrolling into or selecting any of the cells outside of the specified range.  I use this with dashboards so that the user’s screen is always focused on the key information, even if they try to scroll it won’t let them.

'Set the scroll area to a specific range
ActiveSheet.ScrollArea = "A10:D20"
'Reset the scroll area
ActiveSheet.ScrollArea = ""

Scroll to specific location on the worksheet

The code below shows how to scroll to a specific row or column.  Change the ScrollRow and ScrollColumn values to meet your requirements.

'Scroll to a specific row and column
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 10

Scroll by a specific number of rows or columns

SmallScroll and LargeScroll can be used to scroll the window, using the active cell as a start point.  The good news is that even if the code tries to scroll the horizontal or vertical position to be less than Row 1 or Column A the code will not create an error.

'Scroll horizontally or vertically by a specific number of rows or columns
ActiveWindow.SmallScroll Up:=100
ActiveWindow.SmallScroll Down:=50
ActiveWindow.SmallScroll ToRight:=8
ActiveWindow.SmallScroll ToLeft:=8
'The SmallScroll method can be applied within a single line
ActiveWindow.SmallScroll Up:=20, ToRight:=10
'The SmallScroll method can be applied without referencing the direction.
'The arguments must be presented in the order show below
'ActiveWindow.SmallScroll ([Down], [Up], [ToRight], [ToLeft])
ActiveWindow.SmallScroll 20, , 30,
'LargeScroll also exists as a method.  LongScroll will scroll a page at a time,
'rather than individual row/column
ActiveWindow.LargeScroll Down:=2, ToLeft:=1

The values can be negative numbers.  Up:=-20 is equivalent to Down:=20.  The same is true for ToLeft and ToRight.

Headshot Round

About the author

Hey, I’m Mark, and I run Excel Off The Grid.

My parents tell me that at the age of 7 I declared I was going to become a qualified accountant. I was either psychic or had no imagination, as that is exactly what happened. However, it wasn't until I was 35 that my journey really began.

In 2015, I started a new job, for which I was regularly working after 10pm. As a result, I rarely saw my children during the week. So, I started searching for the secrets to automating Excel. I discovered that by building a small number of simple tools, I could combine them together in different ways to automate nearly all my regular tasks. This meant I could work less hours (and I got pay raises!). Today, I teach these techniques to other professionals in our training program so they too can spend less time at work (and more time with their children and doing the things they love).

Do you need help adapting this post to your needs?

I'm guessing the examples in this post don't exactly match your situation. We all use Excel differently, so it's impossible to write a post that will meet everybody's needs. By taking the time to understand the techniques and principles in this post (and elsewhere on this site), you should be able to adapt it to your needs.

But, if you're still struggling you should:

  1. Read other blogs, or watch YouTube videos on the same topic. You will benefit much more by discovering your own solutions.
  2. Ask the 'Excel Ninja' in your office. It's amazing what things other people know.
  3. Ask a question in a forum like Mr Excel, or the Microsoft Answers Community. Remember, the people on these forums are generally giving their time for free. So take care to craft your question, make sure it's clear and concise.  List all the things you've tried, and provide screenshots, code segments and example workbooks.
  4. Use Excel Rescue, who are my consultancy partner. They help by providing solutions to smaller Excel problems.

What next?
Don't go yet, there is plenty more to learn on Excel Off The Grid.  Check out the latest posts:

Leave a Reply

Your email address will not be published. Required fields are marked *