vba 按今天和之后的日期过滤数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28443210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:10:31  来源:igfitidea点击:

Filter Data by Today's Date and After

excelvbaexcel-vbafilter

提问by New2VBA

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.

我有可以追溯到 2010 年并持续到 2029 年的数据。我想创建一个宏来过滤仅包括今天和未来日期的数据。

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:$T47").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

回答by L42

Try this:

尝试这个:

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

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

这只会显示大于或等于今天的日期。哈。