ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Filter and unfilter (https://www.excelbanter.com/excel-programming/426399-filter-unfilter.html)

Daniel Bonallack

Filter and unfilter
 
I have a very simple macro that saves the user from having to go to the
custom autofilter:

Selection.AutoFilter Field:=8, Criteria1:="<Holiday", Operator:=xlAnd

I want to switch this to a toggle - so that if field 8 is already filtered,
then it will run the command

Selection.AutoFilter Field:=8

What is the IF statement to use to determine if field 8 is already filtered?

Thanks in advance
Daniel





Nigel[_2_]

Filter and unfilter
 
Use the Filters collection but first check there is a filter in place else
it will fail, for example

With Selection
If .AutoFilterMode Then
If .AutoFilter.Filters(8).On Then

Else

End If
End If
End With

--

Regards,
Nigel




"Daniel Bonallack" wrote in
message ...
I have a very simple macro that saves the user from having to go to the
custom autofilter:

Selection.AutoFilter Field:=8, Criteria1:="<Holiday", Operator:=xlAnd

I want to switch this to a toggle - so that if field 8 is already
filtered,
then it will run the command

Selection.AutoFilter Field:=8

What is the IF statement to use to determine if field 8 is already
filtered?

Thanks in advance
Daniel






Daniel Bonallack

Filter and unfilter
 
Thanks - just what I needed.

"Nigel" wrote:

Use the Filters collection but first check there is a filter in place else
it will fail, for example

With Selection
If .AutoFilterMode Then
If .AutoFilter.Filters(8).On Then

Else

End If
End If
End With

--

Regards,
Nigel




"Daniel Bonallack" wrote in
message ...
I have a very simple macro that saves the user from having to go to the
custom autofilter:

Selection.AutoFilter Field:=8, Criteria1:="<Holiday", Operator:=xlAnd

I want to switch this to a toggle - so that if field 8 is already
filtered,
then it will run the command

Selection.AutoFilter Field:=8

What is the IF statement to use to determine if field 8 is already
filtered?

Thanks in advance
Daniel








All times are GMT +1. The time now is 08:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com