AutoFilter

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

AutoFilter

Post by jstevens »

Is it possible to capture by code whether or not an AutoFilter selection was changed.

As an example say there were three columns each having an AutoFilter. It doesn't matter which column was changed just that fact that one changed is what I'm after.

Thanks,
JOhn
Regards,
John

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: AutoFilter

Post by HansV »

Excel doesn't have a specific event that signals a change in the filter.
If you have at least one formula that refers to cells in the filtered range, the Worksheet_Calculate event will occur when the filter is changed. You could use this to inspect the AutoFilter object, but it'd be a lot of work.
Do you really need this, and if so, why?
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: AutoFilter

Post by jstevens »

Hans,

I'll work with the Worksheet_Calcuate event so that when an AutoFilter object is selected it will write a formula referencing the filtered range. I know how to do that. It's just when the AutoFilter is reset to it's normal state (nothing selected) that I would want to clear the formula.

Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: AutoFilter

Post by HansV »

ActiveSheet.AutoFilter.FilterMode is True if a filter is applied (i.e. some rows are hidden), False if no filter is applied (i.e. all rows are shown).
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: AutoFilter

Post by jstevens »

Thank you,
John
Regards,
John

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: AutoFilter

Post by jstevens »

Hans,

How would one incorporate a line of code within a "Private Workbook_SheetCalculate(ByVal Sh as Object)" to write a formula to the ActiveSheet containing the AutoFilter? I have not had much luck.

I had a previous post with my code. The only thing different is that it's now going to a Private Sub.

One more thing...when the AutoFilter is set back to it's normal state (nothing is being filtered) then the formula should be deleted.

Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: AutoFilter

Post by HansV »

You could use something like this:

sh.Range("B1").Formula = "=TODAY()"

Important: you must set Application.EnableEvents to False before this line (and back to True after it). Otherwise, you may end up with an endless loop, causing Excel to crash.
Best wishes,
Hans