Random ScrollArea Errors

mykulpasskwa

Board Regular
Joined
Mar 20, 2018
Messages
66
I'm trying to lock the scroll area on multiple sheets and have it set for when the workbook opens. I've tried a few different kinds of code with varying degrees of success, but all end with getting an error eventually.

The one below is the most recent one I've tried, and it was working fine for the past two days and then today I got a Run-time error' 57121': Application-defined or object-defined error. I used to get the same error with the slightly different code I was using before, but I can't seem to figure out why this randomly happens. When I End debugging mode and run the macro on its own it works fine, but when I open it from scratch I get the error.

Code:
Private Sub Workbook_Open()Dim ws As Worksheet


Set ws = ActiveSheet


wksCalc.ScrollArea = "A1:S35"
wksSemester1.ScrollArea = "A1:M33"
wksSemester2.ScrollArea = "A1:M33"
wksSemester3.ScrollArea = "A1:M33"
wksSemester4.ScrollArea = "A1:M33"


Set ws = Nothing
        
End Sub

Can anyone see what's wrong or know the nature of the error? Google and forum searches haven't left me with many answers.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try something like this:
Code:
Sheets("Calc").ScrollArea = "A1:S35"
Sheets("Semester1").ScrollArea = "A1:M33"
Sheets("Semester2").ScrollArea = "A1:M33"
Sheets("Semester3").ScrollArea = "A1:M33"
Sheets("Semester4").ScrollArea = "A1:M33"
 
Upvote 0
Or if you wanted to do all your sheets you could try this.
It will set all the sheet scroll areas to the same scroll area but will then reset the ones you want different.
Add those sheet names outside the loop.
Code:
'Modified 5/16/2018 4:30 PM  EDT
Application.ScreenUpdating = False
Dim i As Long
For i = 1 To Sheets.Count
Sheets(i).ScrollArea = "A1:M33"
Next
Sheets("Calc").ScrollArea = "A1:S35"
Application.ScreenUpdating = True
 
Upvote 0
Or if you wanted to do all your sheets you could try this.
It will set all the sheet scroll areas to the same scroll area but will then reset the ones you want different.
Add those sheet names outside the loop.
Code:
'Modified 5/16/2018 4:30 PM  EDT
Application.ScreenUpdating = False
Dim i As Long
For i = 1 To Sheets.Count
Sheets(i).ScrollArea = "A1:M33"
Next
Sheets("Calc").ScrollArea = "A1:S35"
Application.ScreenUpdating = True

This is perfect. Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,215,800
Messages
6,126,981
Members
449,351
Latest member
Sylvine

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top