Reputation: 11
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!
Upvotes: 1
Views: 27256
Reputation: 11
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!
Upvotes: 0
Reputation:
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.
Upvotes: 0
Reputation: 29421
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)
Upvotes: 4