Unprotect cells conditionally in Excel

  Desert Andy 12:41 10 Mar 2007
Locked

Hi

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 2007

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
Else
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.

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

Awful clip art from 1994 is being tweeted every hour by a bot

iPhone X vs Samsung Galaxy Note 8

Les meilleurs navigateurs internet 2017