Anyone know of a way to write an If/Then statement based on the successful entry of a protected sheet password? I have a checkbox on my sheet (Checkbox1) for the purpose of modifying specific cells to either have a Locked status or an Unlocked status when the worksheet is protected.
I would like to add a statement to my script that terminates the script (Exit Sub) if the sheet protection password is entered incorrectly. Right now it will propt for the password, but if the users clicks "cancel" or enters the wrong password it will continue running the script. I'm stumpped. Thanks!
I would like to add a statement to my script that terminates the script (Exit Sub) if the sheet protection password is entered incorrectly. Right now it will propt for the password, but if the users clicks "cancel" or enters the wrong password it will continue running the script. I'm stumpped. Thanks!
Code:
Sub CheckBox1_Click()
ActiveSheet.Unprotect
'need to add code here to exit the sub if password not entered correctly
If CheckBox1.Value = True Then
With Worksheets("Sheet1")
.Range("H10:J10").Locked = True
End With
Else
With Worksheets("Sheet1")
.Range("H10:J10").Locked = False
End With
End If
ActiveSheet.Protect Password:="mypass"
End Sub