Consulting

Results 1 to 4 of 4

Thread: Solved: Conditional Protection (locking) of a Row

  1. #1

    Solved: Conditional Protection (locking) of a Row

    I have a pair of macros linked to option boxes, returning a value of 1 or 2 in linked cell G4. What is the best (simplest) way to:

    1. lock cells c11:k11 if cell G4 reads 1
    2. unlock cells c11:k11 if cell G4 reads 2?

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Give this a try.
    [vba]
    Option Explicit

    Private Sub Worksheet_Calculate()

    Dim Pass As String

    Pass = "MyPassword"
    ActiveSheet.Unprotect Password:=Pass
    If Range("G4").Value = 1 Then
    Range("C11:K11").Locked = True
    ElseIf Range("G4").Value = 2 Then
    Range("C11:K11").Locked = True
    End If
    ActiveSheet.Protect Password:=Pass, Contents:=True, Scenarios:=True, DrawingObjects:=True

    End Sub
    [/vba]

    Also add a formula that will force this to trigger. So if G4 is the linked cell, in any other cell put =G4.

  3. #3
    Even I can see that this is going to work. Thanks!

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

Posting Permissions

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