i have an excel with 500 rows. i have the code that if the cells in column F have the value 500 it will lock the cells. But... if someone tries to modify something today in the last 2 rows ( that are always yesterday and the day before yesterday ) it should be able to do that. So if today is 23.02.2016 he can modify the last 2 rows but not the rest.
Sub Lock_cells(ByVal Target As Range) ActiveSheet.Unprotect Dim cl As Range If Target.Column = 6 Then For Each cl In Target.Cells If UCase(cl.Value) = UCase("500") And cl.Column = 6 Then Range("a" & cl.Row & ":f" & cl.Row).Locked = True Else Range("a" & cl.Row & ":f" & cl.Row).Locked = False End If Next End If ActiveSheet.Protect End Sub
Can it work if i put the sub in BeforeClose or on Open and verify if the date condition is true ? Thank you.
UCase("500")
and why is text masquerading as a number? Treating true numbers as numbers is preferential unless the column contains mixed data types. Where are the dates? – user4039065