ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   problem with protecting sheet (https://www.excelbanter.com/excel-programming/395282-problem-protecting-sheet.html)

bernd

problem with protecting sheet
 
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?


bernd

problem with protecting sheet
 
I've also tried:

Private Sub Worksheet_Activate ( )
Dim i as variant
i = Status
If i = "xx" Then
Activesheet.Unprotect Password:= "pass"
Else: Activesheet.Protect Password:= "pass"
End If
End Sub

I don't get errors on this code, but it doesn't work. Sheet 1 stays
protected, with the text xx in the cell with reference "status"


Cheetahke

problem with protecting sheet
 
Hi bernd

You refer to a range on the active sheet, you have to refer to a range on
sheet 2
Try this:

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


"bernd" wrote:

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?




All times are GMT +1. The time now is 03:25 PM.

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