Filter Date with Macro Today and Past Dates

318 views Asked by At

I'm trying to make a macro to filter dates in Column F to show today's date and anything that past due like dates that in in the past but also delete the entire rows with future dates i cant seem to get it working.

For example:Today's date is 9/9/2020

9/7/2020 - Show

9/8/2020 - Show

9/9/2020 - Show

9/10/2020 - Delete enter image description here

9/11/2020 - Delete

Sub Macro11() Macro11 Macro
Rows("1:1").Select
Range("B1").Activate
Selection.AutoFilter
Selection.AutoFilter
ActiveSheet.Range("$A$1:$F$225").AutoFilter Field:=6, Criteria1:=1, _
    Operator:=11, Criteria2:=0, SubField:=0
ActiveSheet.Range("$A$1:$F$225").AutoFilter Field:=6, Criteria1:="<(NOW)", _
    Operator:=xlAnd
Range("G228").SelectEnd Sub
1

There are 1 answers

2
Fabrizio On BEST ANSWER

@Brian Russell why use Autofilter?!? You simply loop each cell backwards and if the date are > that today you'll delete the row. a basic code (I suppose that your column with date are F, like your sample image)

Sub delfutureDays()
Dim cl As Long
For cl = Range("F2").End(xlDown).Row To 2 Step -1
    If Cells(cl, "F") > Date Then Rows(cl).EntireRow.Delete
Next
End Sub