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!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Assuming the Worksheet_change is in Measure_sheet.

Take the 0 out and try just ""
Or Change .text to .value

Jason's
 
Last edited:
Upvote 0
The .Locked property of a cell describes what happens when the sheet is protected. To prevent the user from changing a cell both the cell must be locked AND the sheet must be protected.
 
Upvote 0
I knew that but I tried it both ways anyway. I have tried so many iterations I was grasping at straws.

The only other thing I can think of is that Measure_Cut!E3 is a drop down list. Would that make any difference? I think not but I have been wrong once or twice.
:stickouttounge:

The .Locked property of a cell describes what happens when the sheet is protected. To prevent the user from changing a cell both the cell must be locked AND the sheet must be protected.
 
Upvote 0
If you put this in Measure_Cut's code module, (and don't protect Notching with a password), this should work


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    With ThisWorkbook.Sheet("Notching")
        .UnProtect
        .Range("E16:E18").Locked = (Me.Range("E3").Value <> 0)
        .Protect
    End If
End Sub
 
Upvote 0
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
Still no joy.

If you put this in Measure_Cut's code module, (and don't protect Notching with a password), this should work


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    With ThisWorkbook.Sheet("Notching")
        .UnProtect
        .Range("E16:E18").Locked = (Me.Range("E3").Value <> 0)
        .Protect
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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