The Scrollarea property returns or sets the range that the worksheet allows to scroll by using a A1-style range reference (string type). After you set up the worksheet scrolling area, users cannot select cells outside of the scrolling area, but you can still select other objects (such as graphics, buttons, and so on) that are outside the range, and some of the corresponding features of the worksheet may be blocked (for example, a worksheet full selection, an entire row, or an entire column, and so on).
The Project Management window in VBE select the corresponding Worksheet object, and then set the Scrollarea property in its Properties window to limit the scrolling area on the worksheet as shown in the figure.
However, Excel does not remember this setting, and when you open the workbook again, the Scrollarea property is reset and the user must reset the Scrollarea property to limit the scrolling area on the worksheet. The workaround is to use code to set the Scrollarea property when the workbook is opened, as shown in the following code.
Code:
Copy Code code as follows:
#001 Private Sub Workbook_Open ()
#002 Sheet1.scrollarea = "B4:h12"
#003 End Sub
Code resolution:
The Open event for the workbook, which sets the scrolling area of the SHEET1 worksheet to the "B4:h12" range when the workbook is opened.
If you need to cancel the limit of the scrolling area, set the Scrollarea property value to null, as shown in the following code.
Sheet1.scrollarea = ""