ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   toggle between autofilter Criteria1:= "*" and "all" (https://www.excelbanter.com/excel-programming/403144-toggle-between-autofilter-criteria1-%3D-%2A-all.html)

Mike Gallagher[_2_]

toggle between autofilter Criteria1:= "*" and "all"
 
I'm using autofilter to collapse and expand a range based on value of Criteria1
I would like to use code to be able to alternate between Criteria1:="1" and
Criteria1:="All"

This is the code that i thought would work but hasn't -

Dim filtcrit

filtcrit = Criteria1

With ActiveSheet
If filtcrit = 1 Then
Selection.AutoFilter Field:=1

Else
Selection.AutoFilter Field:=1, Criteria1:="1"

End If
End With

sebastienm

toggle between autofilter Criteria1:= "*" and "all"
 
Hi,
try:
''' --------------------------------------

Sub test()
Dim wsh As Worksheet
Set wsh = ActiveSheet
With wsh
If .AutoFilter.Filters(1).On Then
.AutoFilter.Range.AutoFilter Field:=1
Else
.AutoFilter.Range.AutoFilter Field:=1, Criteria1:="=1"
End If
End With
End Sub
''' ---------------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com
<http://www.ready-reports.com


"Mike Gallagher" wrote:

I'm using autofilter to collapse and expand a range based on value of Criteria1
I would like to use code to be able to alternate between Criteria1:="1" and
Criteria1:="All"

This is the code that i thought would work but hasn't -

Dim filtcrit

filtcrit = Criteria1

With ActiveSheet
If filtcrit = 1 Then
Selection.AutoFilter Field:=1

Else
Selection.AutoFilter Field:=1, Criteria1:="1"

End If
End With


Mike Gallagher[_2_]

toggle between autofilter Criteria1:= "*" and "all"
 
Thank you, that will work well

"sebastienm" wrote:

Hi,
try:
''' --------------------------------------

Sub test()
Dim wsh As Worksheet
Set wsh = ActiveSheet
With wsh
If .AutoFilter.Filters(1).On Then
.AutoFilter.Range.AutoFilter Field:=1
Else
.AutoFilter.Range.AutoFilter Field:=1, Criteria1:="=1"
End If
End With
End Sub
''' ---------------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com
<http://www.ready-reports.com


"Mike Gallagher" wrote:

I'm using autofilter to collapse and expand a range based on value of Criteria1
I would like to use code to be able to alternate between Criteria1:="1" and
Criteria1:="All"

This is the code that i thought would work but hasn't -

Dim filtcrit

filtcrit = Criteria1

With ActiveSheet
If filtcrit = 1 Then
Selection.AutoFilter Field:=1

Else
Selection.AutoFilter Field:=1, Criteria1:="1"

End If
End With



All times are GMT +1. The time now is 11:45 AM.

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