protect sheet when cell is not blank

W

Wanna Learn

Hello
In VBA - Cell N11 is blank, but whenever Cell N11 is not blank I want to
protect the entire sheet with the word "pass"
thanks in advance
 
J

JLatham

This goes into the worksheet's code module (right-click on the sheet's name
tab and choose View Code from the list, then copy and paste this into the
module presented to you). Naturally cell N11 is going to have to be unlocked
or you won't be able to clear the entry in it once the sheet goes into
protected state:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$N$11" Then
Exit Sub
End If
If IsEmpty(Target) Then
ActiveSheet.Unprotect Password:="PASS"
Else
ActiveSheet.Protect Password:="PASS"
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top