问题
I'm trying to write a VBA to filter a file.
I filtered it for Field 5 and 8 but i also want field 7 to filter for date - i want the file to show all lines that are today + 14 day and filter the rest.
thanks
Sub Filter()
'
Sheets("CP").Select
Range("a3:d" & Cells(Rows.Count, "e").End(xlUp).Row).AutoFilter Field:=5, Criteria1:="Plan"
Range("a3:d" & Cells(Rows.Count, "e").End(xlUp).Row).AutoFilter Field:=18, Criteria1:="No"
End Sub
回答1:
Please try.
Range("a3:d" & Cells(Rows.Count, "e").End(xlUp).Row).AutoFilter Field:=7,
Criteria1:=">=" & Date(), Operator:=xlAnd, Criteria2:="<" & Date() +14
回答2:
i added
' Range("a3:d" & Cells(Rows.Count, "e").End(xlUp).Row).AutoFilter Field:=7,
Criteria1:="<=" & Date + 14, Operator:=xlAnd, Criteria2:="<" & Date + 14 '
it seems to work.
thanks
来源:https://stackoverflow.com/questions/48522990/excel-vba-filter-by-date