ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   protect sheet when cell is not blank (https://www.excelbanter.com/excel-discussion-misc-queries/216583-protect-sheet-when-cell-not-blank.html)

Wanna Learn

protect sheet when cell is not blank
 
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

JLatham

protect sheet when cell is not blank
 
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


"Wanna Learn" wrote:

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



All times are GMT +1. The time now is 10:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com