Unprotect cells conditionally in Excel

  Desert Andy 12:41 10 Mar 07


I have locked a worksheet, and would like to unhide text and unprotect a cell if the user puts certain text into a different cell. Is this possible?

  VoG II 13:04 10 Mar 07

Something like this. Right click the sheet tab, select View Code. Copy and paste in:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Address(False, False) <> "A1" Then Exit Sub
If UCase(Target.Value) = "UNLOCK" Then
ActiveSheet.Unprotect Password:="pw"
Range("D8").Locked = False
On Error Resume Next
Range("D8").Locked = True
On Error GoTo 0
ActiveSheet.Protect Password:="pw"
End If
End Sub

Close the code window. Typing 'unlock' (without quotes) into A1 should unprotect the sheet and unlock D8. Typing anything else into A1 should lock D8 and protect the sheet.

This thread is now locked and can not be replied to.

What is ransomware and how do I protect my PC from WannaCry?

What I learned from my mentor, Oscar-winning VFX supervisor Phil Tippett

Siri vs Google Assistant