problem with protecting sheet

B

bernd

hello,

When selecting a sheet1 the sheet is protected.

Depending on the value (xx) in a cell on sheet2, I want sheet 1 to be
unprotected or stay protected.
I made a reference to the cell on sheet2: status

I created the following code but doesn't work.

Private Sub Worksheet_Activate ()
If Range(status) = "xx" Then
Activesheet.Unprotect Password:= "pass"
Else: Activesheet.Protect Password:= "pass"
End If
End Sub

How do I solve this?
 
G

Guest

try it like this:

Private Sub Worksheet_Activate()

If ThisWorkbook.Sheets("Sheet2").Range("Status") = "xx" 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