Excel VBA Saving autofilter settings with dates

后端 未结 3 1711
鱼传尺愫
鱼传尺愫 2021-01-24 01:34

I have a part of a macro that stores the autofilter settings before clearing the filter, so it can reapply them later. The code is as follows:

Dim FilterArray()
         


        
3条回答
  •  广开言路
    2021-01-24 02:14

    Note, this solution below is true of Excel 2010, I cannot find information on Excel 2013, but it is possible the same problem exists.
    If you record a macro while running an auto date filter, you will notice the values are stored in the Criteria2 parameter, and Criteria1 is not used:

    Range.AutoFilter Field:=2, Operator:=xlFilterValues, Criteria2:=Array(2, "8/10/2015", 2, "8/20/2015")
    

    Trying to access the Criteria2 parameter from VBA causes an "Application-defined or object-defined error".
    At the time of writing this answer, the only way I know of saving this autofilter information is by reading the XML data inside the xlsx file. Working code here:
    Get Date Autofilter in Excel VBA

提交回复
热议问题