Excel VBA limits the scrolling area code for worksheets _vba

Source: Internet
Author: User
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 = ""

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.