Solved

Excel VBA -- Set multiple scroll areas

Posted on 2014-10-29
1
1,186 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
1 Comment
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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,…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now