vba 在excel vba中过滤两个日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40820757/
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
Filtering between two dates in excel vba
提问by PrivateResearch
I need help to filter between two dates and it's giving me an error:
我需要帮助在两个日期之间进行过滤,但它给了我一个错误:
Named argument not found
未找到命名参数
my code
我的代码
Dim StartDate As String
Dim EndDate As String
'
StartDate = Date
EndDate = Date + 365
'
ActiveSheet.AutoFilter Field:=7, Criteria1:=">=StartDate", Operator:=xlAnd, Criteria2:="<=EndDate"
Any help would be much appreciated!
任何帮助将非常感激!
回答by user3598756
if your dates are actual Date
values (i.e. not String
ones looking like dates), then go like this:
如果您的日期是实际Date
值(即不是String
看起来像日期的日期),那么像这样:
Dim StartDate As Date
Dim EndDate As Date
StartDate = Date
EndDate = Date + 365
ActiveSheet.Range("A1:AO1").AutoFilter Field:=7, Criteria1:=">=" & CDbl(StartDate), Operator:=xlAnd, Criteria2:="<=" & CDbl(EndDate)
回答by user3598756
I posted a sample file on my google drive.
我在我的谷歌驱动器上发布了一个示例文件。
https://drive.google.com/open?id=0B2w6b7-P-pX1R0dlTlFUSl9xZlE
https://drive.google.com/open?id=0B2w6b7-P-pX1R0dlTlFUSl9xZlE
I can describe the logic, but it's just easier for you to download it, play around with it, and see the mechanics of it.
我可以描述其中的逻辑,但对您来说,下载它、使用它并查看它的机制会更容易。
回答by PrivateResearch
Basic logic was the issue... mix up of the start and end date logic (should be EndDate = Date and StartDate = Date - 365).
基本逻辑是问题......混合开始和结束日期逻辑(应该是 EndDate = Date 和 StartDate = Date - 365)。
Sorry for the troubles!
抱歉给您带来麻烦!