Results 1 to 6 of 6

Lock and Unlock Sheets based on Cell values

Threaded View

  1. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Lock and Unlock Sheets based on Cell values

    Quote 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
    Last edited by DonkeyOte; 02-01-2011 at 05:23 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1