Solved

Excel VBA -- Set multiple scroll areas

Posted on 2014-10-29
1
1,493 Views
Last Modified: 2014-10-29
In Excel, I'm using VBA (see below) to limit the scroll area upon opening a spreadsheet.

Private Sub Workbook_Open()

    'Locks Scroll Area
    Sheet1.ScrollArea = "C14:D20"
    
End Sub

Open in new window


This solution works great except that I need several (non-adjacent) cell ranges.    Unless not possible otherwise, I'd prefer to NOT use the "Lock cell/sheet" feature.

I attempted to tweak the code (see below); however, it throws an error message.   How can I use multiple cell ranges as part of the VBA below?

Private Sub Workbook_Open()

    'Locks Scroll Area
    Sheet1.ScrollArea = "C14:D20, D23, B28"
    
End Sub

Open in new window

0
Comment
Question by:ExpExchHelp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40411097
The scroll area must be a contiguous range (i.e., all cells defined in a single, rectangular area with no gaps).  You can't use multiple ranges.

Instead, you may wish to protect the sheet and limit user selection to just the unlocked cells.  The behavior will be the same; users will only be able to select cells, either through mouse-click or [Tab] or arrow movement.
 protect
Regards,
-Glenn
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question