Results 1 to 4 of 4

Thread: VBA Code To Protect Sheet With Only A Few Cells Unlocked

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    78
    Rep Power
    12

    VBA Code To Protect Sheet With Only A Few Cells Unlocked

    HI

    Workbook has 2 sheets - I need a VBA Code to lock all the cells in a Sheet called "Groups" except for cell range C21:L21 & C32:M36 and also sheet called "Teams" to lock all the cells except C4

    I will assign to a activeX button so could the code please have a password box attached

    Cheers

    Rich

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Try this

    Code:
    Sub LockCells()
    
        Const strPWD As String = "Password"
        If strPWD = InputBox("Enter password to protect", "Protect sheets") Then
            With Worksheets("Group")
                .Unprotect strPWD
                .Cells.Locked = True
                .Range("C21:L21,C32:M36").Locked = False
                .Protect strPWD
            End With
            With Worksheets("Team")
                .Unprotect strPWD
                .Cells.Locked = True
                .Range("C4").Locked = False
                .Protect strPWD
            End With
        End If
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Member
    Join Date
    Dec 2012
    Posts
    78
    Rep Power
    12
    Where do I place the code...new module....if I want to chande the password where do I do this please

    Cheers

    Rich

  4. #4
    Member
    Join Date
    Dec 2012
    Posts
    78
    Rep Power
    12
    No luck with getting this to work...where do I place the code please....where do I set the password

    Rich

Similar Threads

  1. Highlighting All the Cells of Active sheet which contains a particular String:
    By littleiitin in forum Excel and VBA Tips and Tricks
    Replies: 6
    Last Post: 10-18-2013, 04:19 PM
  2. Replies: 14
    Last Post: 06-24-2013, 06:17 PM
  3. Replies: 1
    Last Post: 06-12-2013, 07:42 PM
  4. Replies: 13
    Last Post: 06-10-2013, 09:05 AM
  5. Adding charts via code to a protected sheet
    By Rasm in forum Excel Help
    Replies: 2
    Last Post: 11-14-2012, 05:11 PM

Posting Permissions

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