someone asked me to show them how to lock a range of cells after one day now
I'm going to show you how to I did it now
his application was involving some kind of a game where they could make
selections and I assumed it was players for a team or or something like that and
and they he wanted them to select one day and then after that
they'd be locked so here I have an instance where I I go and I try to
change anything and it's going to tell me that it's locked
and so I have a look I have a cells locked message come up now what I've
done is I don't know anything about the games or anything else but there's a
drop-down on each of the cells that will allow you to pick a color
and now so the cells that are the cells that are before today are locked and so
here's your message come up again now if we go down to and make one for today
let's make this green and it instantly puts in the date for today now since
it's today's date I can change any of them and it won't have a problem with it
so basically the ones that I did yesterday I try to change them and it
gives me the error message so anything that was entered today is still you can
still edit it anything that was entered yesterday or earlier you're not able to
enter or you're not able to change it
okay so let me show you my code so this code is based on a worksheet and and a
worksheet and is based on a change so that I've right clicked on the sheet tab
and I've said view code and then I've selected worksheet and I've states
change and so now what I have done is in this first little loop here is I have
unprotected the sheet so it allows me to enter the date for cells that I'm
entering data on now I have a for loop from x equals first of all x equals 2
because I've heading rows in there for x equals to 2 to 32 I'm doing a for loop and I
say if worksheet count a so I'm checking to see if there's anything in there
cells range X 1 to X 10 does not equal 0 and
cells X 11 which is the date value is equal to nothing then cells X 11 value
equals date so it's putting in it's putting in the date into cell X 11 now
else go to ende and ende is just before the next and I do the next loop now the
next thing I do is I call an application called not today or a sub call not today
and in this sub I once again do a for loop from X from 2 to 32 in this
one I test is date it's a is date function to check whether it is there is
a date and there or not and if there is a date in there the cells value if it's
less than today active range I hide and protect his password and
range is cell X 1 to X 11 equals lock equals true so this will lock anything
that is not today that it is a date initially I was having problems because
a blank cell is not is less than today so I needed to put in the is date
function and cells value is less than today and so cells X 1 to X 11 locked
equals true the end if I'm going next for my loop and then I protect sheets
sheets 1 protect protection in my password is test so that's how you lock
cells after one day please subscribe