Locking cells based on criteria

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
I would like to lock and gray out cells in rows 8 to last row where the weekending date is less than cell E1. That way once the week passes, people will not have the chance to change past data. However, if I change the weekending date and it is less than the date of the header row, those cells have to go back to being unlocked and not gray anymore. Thanks in advance.
Book1
ABCDEFGHIJKL
1Currentweekendingdate08-09-08
2
3
4Pleaseenterweekendingprojections
5
6
7
806/07/0806-14-0806-21-0806-28-0807-05-0807-12-0807-19-0807-26-0808-02-0808-09-0808-16-08
9677515539
10140618020
11612961644
12975174450
13770617674
14041836335
15469222191
16448879011
17480116388
18252647816
19785319920
20829255133
21579968702
22971333936
23541229952
24975905382
25357559305
26437446397
27965397692
28143889210
29510604187
30932862657
31280598482
32
Sheet1
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
This should do it for you:

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#007F00">'   Code goes in the Worksheet specific module</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> rng <SPAN style="color:#00007F">As</SPAN> Range<br>        <SPAN style="color:#007F00">'   Set Target Range</SPAN><br>        Set rng = Target.Parent.Range([A8], Cells(Columns.Count))<br>             <SPAN style="color:#007F00">'   Only look at single cell changes</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Only look at that range</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Intersect(Target, rng) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Action if Condition(s) are met</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Target.Value < <SPAN style="color:#00007F">Date</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>                ActiveSheet.Unprotect "bigdog"<br>                    Range(Target.Address, Cells(Rows.Count, Target.Column).End(xlUp)).Locked = <SPAN style="color:#00007F">True</SPAN><br>                ActiveSheet.Protect "bigdog"<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Note that you'll need to unlock the input cells first. ;)

HTH,
 
Last edited:
Upvote 0
what do you mean unlock & input cells?

Range A8:IV31 (or further down) will need to be unlocked (Cells-->Protection-->Uncheck Locked) prior to using the code, otherwise the sheet will be protected with all locked cells and you won't be able to enter anything.

By default all cells on a worksheet are set to Locked status. If you want to use worksheet protection you need to unlock the cells with which you want to interact first.
 
Upvote 0

Forum statistics

Threads
1,214,399
Messages
6,119,279
Members
448,884
Latest member
chuffman431a

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