toggle between autofilter Criteria1:= "*" and "all"

M

Mike Gallagher

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
 
S

sebastienm

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
''' ---------------------------------------------
 
M

Mike Gallagher

Thank you, that will work well

sebastienm said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help me4 2
Problem with AutoFilter 8
Problem using Autofilter 1
Excel VBA filtering 2
Selection.AutoFilter Issue 1
Autofilter in a macro 1
AutoFilter Criteria in VBA 5
Autofilter sorting. 3

Top