Try this. You'll need to paste this in the respective sheet module. Note the name of the command button. This has to be consistent with what's on your sheet. In your example above, it was CommandButton1
Code:
Private Sub CommandButton1_Click()
Dim strPassword As String
Const strActualPassword As String = "ABCD"
strPassword = InputBox("Please enter the password", "Protect/Unprotect Sheet")
If strActualPassword = strPassword Then
If Me.CommandButton1.Caption = "PROTECT SHEET" Then
Me.CommandButton1.Caption = "UNPROTECT SHEET"
UnlockCells
Me.Protect Password:=strPassword
Else
Me.CommandButton1.Caption = "PROTECT SHEET"
Me.Unprotect Password:=strPassword
End If
Else
MsgBox "Invalid Password"
End If
End Sub
Sub UnlockCells()
Me.Range("B10:T10,B16:T18,B24:T28").Locked = False
End Sub
Bookmarks