Hi SamT,
Here is code for above procedure I'm trying to modify/adjust to use across multiple sheets. I'm attaching test sheet I'm working off, passwords and ranges provided below.Workbook Protection v.2.xlsm
ThisWorkbook Module
Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
LockUser GetUserInputRange(AllInputCells:=True)
End Sub
Private Sub Workbook_Open()
UnlockInputCells
End Sub
Module 1
Option Explicit
'Admin Passwords
Public Const PWD_REAL As String = "test" ' this is the password the worksheet is actually locked with
Public Const NAMED_ALL As String = "ADMIN_WS" ' Named Range that includes all input cells
'User passwords
Public Const PWD_INPUT1 As String = "ppe" ' password to unlock INITAL WORKSCOPE - NAMED_RANGE1
Public Const PWD_INPUT2 As String = "ppe1" ' password to unlock UPDATE SECTION - NAMED_RANGE2
Public Const PWD_INPUT3 As String = "tech" ' password to unlock STAMPED DATA - NAMED_RANGE3
Public Const PWD_INPUT4 As String = "tech1" ' password to unlock EMPTY CELL - NAMED_RANGE3
'Name Ranges
Public Const NAMED_RANGE1 As String = "PPE_LOCK" ' Named Range for user 1 (PPE INITAL WORKSCOPE)
Public Const NAMED_RANGE2 As String = "PPE_UNLOCK" ' Named Range for user 2 (PPE NEW UPDATE ONLY)
Public Const NAMED_RANGE3 As String = "TECH_LOCK" ' Named Range for user 3 (TECH SIGN OFF ON WS)
Public Const NAMED_RANGE4 As String = "TECH_UNLOCK" ' Named Range for user 4 (TECH WIP ACTION ITEM)
Module 2
Option Explicit
Sub UnlockInputCells()
UnlockUser GetUserInputRange
End Sub
Sub LockInputCells()
LockUser GetUserInputRange
End Sub
'-----------------------------------------------
Function GetUserInputRange(Optional AllInputCells As Boolean = False) As Range
Dim rng As Range, strInputMsg As String
Set rng = Nothing
strInputMsg = "Enter your password to edit." & vbCrLf & vbCrLf _
& "Press cancel if you just want to look at the report."
If AllInputCells Then
Set rng = ThisWorkbook.Names(NAMED_ALL).RefersToRange
Else
Select Case InputBox(strInputMsg)
Case PWD_INPUT1
Set rng = ThisWorkbook.Names(NAMED_RANGE1).RefersToRange
Case PWD_INPUT2
Set rng = ThisWorkbook.Names(NAMED_RANGE2).RefersToRange
Case PWD_INPUT3
Set rng = ThisWorkbook.Names(NAMED_RANGE3).RefersToRange
Case PWD_INPUT4
Set rng = ThisWorkbook.Names(NAMED_RANGE4).RefersToRange
Case PWD_REAL
Set rng = ThisWorkbook.Names(NAMED_ALL).RefersToRange
End Select
End If
Set GetUserInputRange = rng
End Function
Private Sub UnlockUser(rngInput As Range)
Dim sht As Worksheet
Set sht = ActiveSheet
If Not rngInput Is Nothing Then
' unprotect the worksheet
Set sht = rngInput.Parent
sht.Unprotect PWD_REAL
' unlock given user input cells
With rngInput
.Locked = False
.Interior.Color = XlRgbColor.rgbAliceBlue
'.Range("A1").Select
End With
' reprotect the worksheet
sht.Protect PWD_REAL
MsgBox "Your input cells have been unlocked."
End If
End Sub
Sub LockUser(rngInput As Range)
Dim sht As Worksheet
Set sht = ActiveSheet
If Not rngInput Is Nothing Then
' If the range includes locked and unlocked cells, .Locked returns Null
If Not rngInput.Locked Or IsNull(rngInput.Locked) Then
' unprotect worksheet
Set sht = rngInput.Parent
sht.Unprotect PWD_REAL
' lock given user fields
With rngInput
.Locked = True
.Interior.ColorIndex = xlColorIndexNone
End With
' reprotect worksheet
sht.Protect PWD_REAL
End If
End If
End Sub
ID