Get Date Autofilter in Excel VBA

前端 未结 3 668
故里飘歌
故里飘歌 2020-12-12 06:13

I am trying to extract Autofilter parameters using VBA. Can any one help me with getting the Autofilter parameters, specifically when a date Autofilter is applied? E.g. Say

3条回答
  •  时光说笑
    2020-12-12 06:34

    I think you're original problem is two fold. First, it appears you're using the Criteria2 field without Criteria1. You only use Criteria2 when you want to create compound criteria, which requires both a Criteria1 argument and an XLAutoFilterOperator argument to combine (e.g. xlAnd or xlOr) with the Criteria2 argument. In your example it appears you are not specifying a Criteria1 argument.

    Second, IIRC all criteria must be provided as a string - which i believe you're second example would cause a problem with the numbers you're trying to pass.

    I'm surprised you don't get an error on the Autofilter line actually.

    Try changing your code to:

    Range.AutoFilter Field:=2, Criteria1:=Array(cstr(2), "8/10/2015", cstr(2), "8/20/2015"), Operator:=xlFilterValues
    
    Print Range.Autofilter.Filters(2).Criteria1(1)
    

提交回复
热议问题