Conditional locking/deleting?

aitzko

New Member
Joined
Apr 1, 2009
Messages
6
Hi,

My question is: I'd like to lock and delete the contents of several cells depending on the content of a different cell. More specifically,

If F4 has any value at all (the options are "Individual", "Individual + Spouse", "Individual + Child" and "Family" -- my spreadsheet is about health care coverage!), I want to lock cells F5 and F6 and delete the contents of A5:AJ5 and A6:AJ6. (Not delete the cell, just the contents)

Is this even possible? Thanks very much in advance!

Amanda
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi and welcome to the Board!!!
Use a WorkSheet_Change Event
Code:
If Target.Address <> "$F$4" Then Exit Sub
ActiveSheet. UnProtect "password"
Range("$F$5:$F$6").Locked = True
Range("$A$5:$AJ$6").ClearContents
ActiveSheet.Protect "password"
End Sub
Goes in the WorkSheet module. RightClick the sheet tab and choose "View Code"
lenze
 
Upvote 0
Thank you both for the very quick response! :)

lenze, thank you! I'm afraid I demonstrate my ignorance, however, when I say that after I put that code in, what do I do? Haha, I have never used the Visual Basic code stuff before, this is entirely new to me. Do I need to click anything to activate that?

Thanks again, and sorry for my woeful ignorance!
 
Upvote 0
Sorry, the 1st line of code got omitted!!!!
Code:
Private Sub Worksheet_change(Byval Target as Range)
If Target.Address <> "$F$4" Then Exit Sub
ActiveSheet. UnProtect "password"
If Target <> "" Then
    Range("$F$5:$F$6").Locked = True
    Range("$A$5:$AJ$6").ClearContents
    ActiveSheet.Protect "password"
End If
End Sub
Place this in the WorkSheet module. Rightclick the sheet tab and choose "View Code" This macro will fire whenever $F$4 is changed.
lenze
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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