Autofilter for multiple columns in excel VBA

邮差的信 提交于 2021-02-11 16:17:50

问题


Can you please let check what is the error in below vba macro? Trying to autofilter two columns based on criteria. I am not able to filter field 8 and field 9 based on below code.

Worksheets("Demo_Sheet").Activate
With Worksheets("Demo_Sheet").Range("A1")
.AutoFilter field:=8, Criteria1:="<=" & Format(Now() + 5, "m/d/yyyy"), Criteria2:=">=" & Format(Now() - 5, "m/d/yyyy"), Operator:=xlAnd
.AutoFilter field:=9, Criteria1:=">=.95"
End With
Range("A1").CurrentRegion.Copy

回答1:


this gave me an answer

Worksheets("Demo_Sheet").Activate
Selection.AutoFilter
ActiveSheet.Range("A1").AutoFilter field:=8, Criteria1:="<=" & Format(Now() + 5, "m/d/yyyy"), Criteria2:=">=" & Format(Now() - 5, "m/d/yyyy"), Operator:=xlAnd
ActiveSheet.Range("A1").AutoFilter field:=9, Criteria1:=">=.95"
Range("A1").CurrentRegion.Copy


来源:https://stackoverflow.com/questions/58821646/autofilter-for-multiple-columns-in-excel-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!