SoFunction
Updated on 2025-03-04

Excel vba restricts scrolling area code for worksheets

The ScrollArea property returns or sets the area in which the worksheet allows scrolling using the A1-style area reference form (string type). After setting up the worksheet scrolling area, the user cannot select cells outside the scrolling area, but can still select other objects outside the area (such as graphics, buttons, etc.). At the same time, some corresponding functions of the worksheet may be prohibited (such as selecting all worksheets, selecting whole rows or columns, etc.).
Select the corresponding worksheet object in the Project Management window in VBE, and then set the ScrollArea property in its properties window to limit the scrolling area in the worksheet, as shown in the figure.

However, Excel will not remember this setting. When the workbook is opened again, the ScrollArea property will be reset. The user must reset the ScrollArea property to limit the scroll area in the worksheet. The solution is to use the code to set the ScrollArea property when the workbook is opened, as shown in the following code.
Code:
Copy the codeThe code is as follows:

#001 Private Sub Workbook_Open()
#002 = "B4:H12"
#003 End Sub

Code parsing:
Open event of the workbook, when opening the workbook, set the scrolling area of ​​the Sheet1 worksheet to the "B4:H12" cell area.
If you need to unlimit the scroll area, you can set the ScrollArea property value to empty, as shown in the following code.
= ""