PDA

View Full Version : VBA Code To Protect Sheet With Only A Few Cells Unlocked



rich_cirillo
07-03-2013, 07:43 PM
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

Excel Fox
07-03-2013, 08:49 PM
Try this



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

rich_cirillo
07-04-2013, 05:31 AM
Where do I place the code...new module....if I want to chande the password where do I do this please

Cheers

Rich

rich_cirillo
07-04-2013, 06:47 PM
No luck with getting this to work...where do I place the code please....where do I set the password

Rich