问题
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!
回答1:
if your dates are actual Date values (i.e. not String ones looking like dates), then go like this:
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)
回答2:
I posted a sample file on my google drive.
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.
回答3:
Basic logic was the issue... mix up of the start and end date logic (should be EndDate = Date and StartDate = Date - 365).
Sorry for the troubles!
来源:https://stackoverflow.com/questions/40820757/filtering-between-two-dates-in-excel-vba