Help with small scroll lock code

g_OUELLET

New Member
Joined
Mar 9, 2009
Messages
43
Trying to set code for a scroll lock so we do not go past Colum E. Can go from A3:E203. But not past column "E" I get Run time Error 9" This is what I have.

Private Sub Workbook_Open()
Worksheets("RestaurantCharges").ScrollArea = "A3:E3"
End Sub

Deleted Image - It was blowing up the page & had actual personal information - Moderator
 
Last edited by a moderator:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
There's nothing wrong with your code, so I'd suspect the sheet name. Does the "RestaurantCharges" sheet really have no space inbetween t/C? Note that when code refers to a sheet name it needs to be exact - even a leading or trailing space can throw it off.

HTH,
 
Upvote 0
Hi
You code works Ok for me, but I change dthe scroll area to meet your range
Code:
Private Sub Workbook_Open()
Worksheets("RestaurantCharges").ScrollArea = "A3:E203"
End Sub
 
Upvote 0
Did you note Smitty's comment about sheet names being EXACT.
 
Upvote 0
The code you posted will only "LOCK" the "RestaurantCharges", nothing else.
Are you saying you want all sheets locked the same way.
 
Upvote 0
The code you posted will only "LOCK" the "RestaurantCharges", nothing else.
Are you saying you want all sheets locked the same way.

Yes all sheets in the workbook. The file name is "Restaurant Charges" inside I have (1) tab "Employee setup" another tab "Sum Sheet" the rest are "Pay Period 1 Pay Period 2 etc.. to "Pay Period 26 these are the sheets i need the scroll lock.
 
Upvote 0
Try this
Code:
Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Employee setup" And ws.Name <> "Sum Sheet" Then
        ws.ScrollArea = "A3:E203"
    End If
 Next
End Sub
 
Upvote 0
Try this
Code:
Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Employee setup" And ws.Name <> "Sum Sheet" Then
        ws.ScrollArea = "A3:E203"
    End If
 Next
End Sub

Thank you, Thank you, Thank you
Works great
Gilles
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

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