Reputation: 11
I am trying to filter data with date greater than given date however it is not picking complete list of date.
Here is my code
Sub Vas()
Startdate="13-10-2020"
Selection.autofilter filed:=6,creteria1:=">=" & startdate
End sub
Above formula is working when i am trying to filter with equal("=") but failed when i use greater than. Can anyone please help!!
Upvotes: 1
Views: 2695
Reputation: 71
One better way to do that is to specify your date as numeric (Long), and use the DateSerial function, like that :
Sub Vas()
Dim StartDate As Long
StartDate = DateSerial(2020, 10, 13)
Selection.AutoFilter Field:=6, Criteria1:=">=" & StartDate
End Sub
Upvotes: 2
Reputation: 55806
Dates are DateTime, not Text, thus:
Sub Vas()
Dim StartDate as Date
StartDate = #10/13/2020#
Selection.Autofilter Field:=6,Criteria1:=">=" & StartDate
' or perhaps, as your default date format is dd-mm-yyyy:
Selection.Autofilter Field:=6,Criteria1:=">=#" & Format(StartDate, "yyyy\/mm\/dd") & "#"
End sub
Upvotes: 1
Reputation: 118
Use this
Sub Vas()
Startdate="13-10-2020"
Selection.autofilter filed:=6,creteria1:=">" & startdate
End sub
Upvotes: 0