
Originally Posted by
Mujahid_Sgd
Just wondering if this code can be extended to n number of sheets.
if "n" is determined by simply however many sheets have both Sign1 & Sign2 ranges then it might be simplest to make this requirement the pre-emptive test:
Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)
Dim rngS As Range
Const C_PWD = "Password"
If [ISREF(Sign1)+ISREF(Sign2)] = 2 Then
sh.Unprotect C_PWD
Set rngS = Union(sh.Range("Sign1"), sh.Range("Sign2"))
rngS.Locked = False
If Not Intersect(Target, rngS) Is Nothing Then
If Application.CountA(rngS) = rngS.Cells.Count Then sh.Protect C_PWD
End If
Set rngS = Nothing
End If
End Sub
or
Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)
Dim rngS As Range
Const C_PWD = "Password"
On Error Resume Next
Set rngS = Union(Range("Sign1"), Range("Sign2"))
On Error GoTo 0
If Not rngS Is Nothing Then
sh.Unprotect C_PWD
rngS.Locked = False
If Not Intersect(Target, rngS) Is Nothing Then
If Application.CountA(rngS) = rngS.Cells.Count Then sh.Protect C_PWD
End If
Set rngS = Nothing
End If
End Sub
Bookmarks