W
wilro85
Currently I'm administrating a large spreadsheet. I've built in an
administrative page so I can quickly unlock and modify the workbook as
needed. However, I'm always interested in making my coding more
efficient.
This is an example of something I think might be fixable:
Private Sub Lockall()
PW = Range("C2").Value
Application.ScreenUpdating = False
ActiveWorkbook.Protect (PW)
Worksheets("Site 1").Protect (PW)
Worksheets("Overview").Protect (PW)
Worksheets("Site 2").Protect (PW)
Worksheets("Site 3").Protect (PW)
Worksheets("Site 4").Protect (PW)
Worksheets("Site 5").Protect (PW)
Worksheets("Site 6").Protect (PW)
Worksheets("Site 7").Protect (PW)
........(Truncated).....
Range("C4").Value = "Locked"
Application.ScreenUpdating = True
End Sub
Such programming becomes tiresome when I add new sheets into the
workbook because I have to modify the protect/unprotect hide/unhide
codes.
Is there a way that I can simplify it using a range? I'd think it
would look something like this, but all my attempts have been met with
errors.
Private Sub Lockall()
PW = Range("C2").Value
Application.ScreenUpdating = False
ActiveWorkbook.Protect (PW)
Worksheets(range("A1":"A25")).Protect (PW)
Range("C4").Value = "Locked"
Application.ScreenUpdating = True
End Sub
administrative page so I can quickly unlock and modify the workbook as
needed. However, I'm always interested in making my coding more
efficient.
This is an example of something I think might be fixable:
Private Sub Lockall()
PW = Range("C2").Value
Application.ScreenUpdating = False
ActiveWorkbook.Protect (PW)
Worksheets("Site 1").Protect (PW)
Worksheets("Overview").Protect (PW)
Worksheets("Site 2").Protect (PW)
Worksheets("Site 3").Protect (PW)
Worksheets("Site 4").Protect (PW)
Worksheets("Site 5").Protect (PW)
Worksheets("Site 6").Protect (PW)
Worksheets("Site 7").Protect (PW)
........(Truncated).....
Range("C4").Value = "Locked"
Application.ScreenUpdating = True
End Sub
Such programming becomes tiresome when I add new sheets into the
workbook because I have to modify the protect/unprotect hide/unhide
codes.
Is there a way that I can simplify it using a range? I'd think it
would look something like this, but all my attempts have been met with
errors.
Private Sub Lockall()
PW = Range("C2").Value
Application.ScreenUpdating = False
ActiveWorkbook.Protect (PW)
Worksheets(range("A1":"A25")).Protect (PW)
Range("C4").Value = "Locked"
Application.ScreenUpdating = True
End Sub