Excel VBA Saving autofilter settings with dates

后端 未结 3 1703
鱼传尺愫
鱼传尺愫 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 01:50

    I've amended your code and it runs now well also with dates in my Excel 2013:

    ' .Criteria1/2 are read as strings with local decimal separator
    ' but for re-setting Criteria1/2 should be in American format ...
    ' so replace local decimal separator by dot - this seems to apply also for dates, 
    ' because dates are also transformed internally to decimal numbers
    FilterArray(f, 1) = Replace(.Criteria1, Application.International(xlDecimalSeparator), ".")
    

    (similar for .Criteria2)

    Regarding your secondary question: see code example in this post: In Excel VBA, how do I save / restore a user-defined filter?

提交回复
热议问题