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()
With FrontPage.AutoFilter.Filters
ReDim FilterArray(1 To .Count, 1 To 3)
For f = 1 To .Count
With .Item(f)
If .On Then
FilterArray(f, 1) = .Criteria1
If .Operator Then
FilterArray(f, 2) = .Operator
If .Operator = xlAnd Or .Operator = xlOr Then
FilterArray(f, 3) = .Criteria2
End If
End If
End If
End With
Next f
End With
This works fine in every situation I have come across except for date fields. In the case of date fields, Criteria1 and Criteria2, cause errors (Application-defined or object-defined error), while Operator returns a value of 7. This happened in Excel 2007 and is still happening in Excel 2013.
I assume the reason this doesn't work is due to the nested way the autofilters treat date fields, but is there a way to make this work with dates? I have seen other problems to do with applying filters to dates, but surely storing them in the first place should be easier?
And a secondary question - what does the value of 7 mean for Operator? I can only find the translation of values 0-2.