New2VBA
New2VBA

Reputation: 347

Filter Data by Today's Date and After

I have data that goes back to the year 2010 and continues into the year 2029. I want to create a macro that filters the data only including today's date and forward.

I recorded the macro below by excluding all dates until today's hoping that it would give me a good place to start, but I'm still very lost.

To make it even more complicated, I don't have every single date available to me, so using a variable for today's date won't always work. So I guess I would need the macro to exclude everything before today's date.

Thanks for the help, I'm really lost and in need of quite a bit.

 Sub Macro1()

    Sheets("Consulta_Lastro").Range("$B$4:$T$9047").AutoFilter Field:=4, Operator:= _
    xlFilterValues, Criteria2:=Array(0, "7/10/2029", 0, "12/20/2028", 0, "12/20/2027", _
    0, "12/20/2026", 0, "12/20/2025", 0, "12/20/2024", 0, "12/20/2023", 0, "12/20/2022", 0, _
    "12/20/2021", 0, "12/22/2020", 0, "12/22/2019", 0, "12/30/2018", 0, "12/30/2017", 0, _
    "12/30/2016", 1, "2/28/2015", 1, "3/31/2015", 1, "4/30/2015", 1, "5/30/2015", 1, _
    "6/30/2015", 1, "7/31/2015", 1, "8/31/2015", 1, "9/30/2015", 1, "10/30/2015", 1, _
    "11/30/2015", 1, "12/30/2015")
End Sub

Upvotes: 1

Views: 9157

Answers (1)

L42
L42

Reputation: 19727

Try this:

Sheets("Consulta_Lastro").Range("$B$4:$T$9047").AutoFilter _
    Field:=4, Criteria1:=">=" & Date

This will only show dates greater than or equal to today's date. HTH.

Upvotes: 2

Related Questions