I am using below code to filter range by 2 dates. I see that filter is set correctly in filter parameters, but only when i press OK button i can see filtering result on my table .. anyone know why ?
Sub Pofiltrujodnajnowszejdaty()
Set First_Cell = Worksheets("Schedule RA_RB").Range("B2")
Set Starting_Date = Range("J1")
Set Ending_Date = Range("K1")
Field = 2
First_Cell.AutoFilter Field:=Field, Criteria1:=">" & Starting_Date, Operator:=xlAnd, Criteria2:="<=" & Ending_Date
End Sub
CodePudding user response:
You have to pass the numeric values of the dates - this is always the case if you are not working on an english system:
First_Cell.AutoFilter Field:=Field, Criteria1:=">" & CLng(Starting_Date), Operator:=xlAnd, Criteria2:="<=" & CLng(Ending_Date)