I'm working on a piece of VBA code which should save & restore the current AutoFilter state in Excel. I've been using the code here for a looong time without any issues, but now I've run into a pretty serious one. Let me illustrate that...
Assume you have a (very simple) table setup with date filtering:
If you would like to get the filtering criteria used programmatically, it will fail:
This is happening for me in Excel 2010. Does anyone know a workaround for this?
A link for the same issue described by someone else on Microsoft TechNet: Excel VBA AutoFilter criteria when Operator is xlFilterValues for Dates This points to Jon von der Heyden's site for a solution, but the site mentions:
Unknown (likely date TreeView filter): To-date I am unable to find a way to capture date filters where the criteria is based on selection from the Tree View control in the Filter drop-down. These criteria are not stored in the Criteria1 or Criteria2 properties. I imagine working out the criteria will involve looping the Range_Field values. Although this would first require that all other field filters be turned-off, something not do-able from a worksheet function and would involve a timer to trigger a sub-routine. Again, I chose to avoid the extra complexity.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…