Locking Cells Based on Drop Down

Raven Jess

New Member
Joined
Jan 4, 2018
Messages
2
Good morning:

I am trying to lock cells G10 and H10 if cell F10 contains anything other than no from the drop down.

I want to do this for each line, 10-19.

All cells on the worksheet should be locked other than B10:B19 thru I10:I19 and I1:14 thru L1:L4.

Can this be done?

Thanks!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Welcome to the Forum!

Perhaps something like this:

Code:
'In the relevant sheet module
Sub Initialise()    'or do this manually to start

    With Me
        .Unprotect Password:="YourPassword"
        .Cells.Locked = True
        .Range("B10:I19").Locked = False
        .Range("I1:L4").Locked = False
        .Protect Password:="YourPassword"
    End With
    
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim r As Range
    
    Me.Unprotect Password:="YourPassword"
    
    For Each r In Intersect(Target, Range("F10:F19"))
        Range("G" & r.Row).Resize(, 2).Locked = UCase(r.Value) <> "NO"
    Next r
        
    Me.Protect Password:="YourPassword"

End Sub
 
Upvote 0
Thank you very much for your response. When I attempt to use this code, I am getting the error: "Run-time error '424': Object required".

I am not sure how to fix this.
 
Upvote 0
Sorry, I should have tested the code ...

Try:

Code:
'In the relevant sheet module
Sub Initialise()    'or you could initialise manually in Excel 

    With Me
        .Unprotect Password:="YourPassword"
        .Cells.Locked = True
        .Range("B10:I19").Locked = False
        .Range("I1:L4").Locked = False
        .Protect Password:="YourPassword"
        Call Worksheet_Change(.Range("F10:F19"))
    End With
    
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim rngMonitored As Range, r As Range
    Set rngMonitored = Intersect(Target, Range("F10:F19"))
    
    If Not rngMonitored Is Nothing Then
        Me.Unprotect Password:="YourPassword"
        For Each r In Intersect(Target, Range("F10:F19"))
            Range("G" & r.Row).Resize(, 2).Locked = UCase(r.Value) <> "NO"
        Next r
        Me.Protect Password:="YourPassword"
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,214
Members
453,024
Latest member
Wingit77

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