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:

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
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,
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,135
Office Version
2013
Platform
Windows
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
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,135
Office Version
2013
Platform
Windows

ADVERTISEMENT

Did you note Smitty's comment about sheet names being EXACT.
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,135
Office Version
2013
Platform
Windows

ADVERTISEMENT

The code you posted will only "LOCK" the "RestaurantCharges", nothing else.
Are you saying you want all sheets locked the same way.
 

g_OUELLET

New Member
Joined
Mar 9, 2009
Messages
43
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.
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,135
Office Version
2013
Platform
Windows
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
 

g_OUELLET

New Member
Joined
Mar 9, 2009
Messages
43
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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,700
Messages
5,512,936
Members
408,924
Latest member
mixalis apokor

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top