Results 1 to 5 of 5

Thread: Protect/Unprotect Cells with VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try something like this:

    Option Explicit
    
    Sub Macro1()
        ActiveSheet.Protect Password:="MyPass", UserInterFaceOnly:=True
        If ActiveSheet.CheckBox1.Value = True Then
            Range("A1:B5").Locked = False
        Else
            Range("A1:B5").Locked = True
        End If
    End Sub
    I am assuming you are using the ActiveX CheckBox. If you are using the Forms CheckBox the check the value of the Linked Cell.

    Also the If statement can be reduced to this:
    Range("A1:B5").Locked = Not ActiveSheet.CheckBox1.Value

Posting Permissions

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