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 = ""
100 Excel VBA Macros

Do you know the fastest way to learn foreign languages?  It is to read, write, speak, and think in that language as often as possible.  Apart from speaking, programming languages are no different.  The more you immerse yourself in that language, the faster you will pick it up.

100 Excel Macros Book

Therefore, what most people like you need is lots of examples that you can practice.  That is why the 100 Excel VBA Macros eBook exists.  It’s the book for all Excel users who want to learn how to read and write Excel macros, save time, and stand out from their peers.  The book contains:

  • 100 example codes to practice reading and writing macros that will embed the language into your thinking.
  • An introduction to macros in Excel to ensure you can implement the VBA code in the book even if you have no prior knowledge.
  • Consistent code layout between examples to enable you to understand the structure and easily customize the code to meet your needs.
  • Downloadable workbook containing all the source code, so the examples can be added to your project to give you the benefit of VBA straight away.

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.



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.

Email Address * First Name *

By entering your email address you agree to receive emails from Excel Off The Grid. We’ll respect your privacy and you can unsubscribe at any time.


Don’t forget:

If you’ve found this post useful, or if you have a better approach, then please leave a comment below.

Do you need help adapting this to your needs?

I’m guessing the examples in this post didn’t exactly meet 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 *