Trying to lock cells in one worksheet depending on value in another worksheet cell

ShutterAce

New Member
Joined
Nov 29, 2011
Messages
15
Hello,

Any ideas as to why this will not run. I've been playing with it all day and can't figure out why it stops after the If statement is evaluated.

I'd bet money it's something minute I'm overlooking but I can't find it. I have changed everything I can think of in the two statements regarding the locking of the cells with no change in behavior.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If ActiveWorkbook.Sheets("Measure_Cut").Range("E3").Text = "0" Then
        ActiveWorkbook.Sheets("Notching").Range("E16:E18").Locked = False
    Else
        ActiveWorkbook.Sheets("Notching").Range("E16:E18").Locked = True
    End If
End Sub

Thank you!
 
This one worked.

Thanks Jason.

Thank you both for trying!

I checked this code below and has no problems.
It has to go in Measure_Cut sheet code.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Application.ScreenUpdating = False
    If Worksheets("Measure_Cut").Range("E3").Text = "0" Then 'Change 0 if needed
        Worksheets("Notching").Select
        ActiveSheet.Unprotect Password:=1234 'Change 1234 to your password
        Worksheets("Notching").Range("E16:E18").Locked = False
        ActiveSheet.Protect Password:=1234 'Change 1234 to your password
        Worksheets("Measure_Cut").Select
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    Else
        Worksheets("Notching").Select
        ActiveSheet.Unprotect Password:=1234 'Change 1234 to your password
        Worksheets("Notching").Range("E16:E18").Locked = True
        ActiveSheet.Protect Password:=1234 'Change 1234 to your password
        Worksheets("Measure_Cut").Select
Application.ScreenUpdating = True
Application.EnableEvents = True
    End If
End Sub
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,469
Messages
6,124,989
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top