Clear cell if the date in the cell is less than a cutoff date

PistolPete123

New Member
Joined
Oct 3, 2018
Messages
1
Hello everyone,

This is my first post and I have been stuck for a bit trying to find a solution. I am trying to clear any cell in column F if the date inside the cell is less than the current date minus 7 days. Also the cells in column F have formulas which calculate a date.

What I tried so far hasn't worked:

Dim currentDate As Date
currentDate = DateAdd("d", -7, Date)
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "F").End(xlUp).Row
With ActiveSheet.Range("F2:F" & Lastrow)
.AutoFilter Field:=1, Criteria1:="<" & currentDate, Operator:=xlFilterValues
.SpecialCells(xlCellTypeVisible).Range.Delete
End With
ActiveSheet.AutoFilterMode = False
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You could have your formula only display valid dates...

=IF(YourDateFormulaHere < Today()-7, "", YourDateFormulaHere)
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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