Reset AutoFilter in code

B

Brian Bermingham

Hi

I know how to remove AutoFilter.
Worksheets("Absence").AutoFilterMode = False

But how can I leave the autofilter in place just removing any applied filter?
Some thing like AutoFilter.reset !

Thanks

Brian
 
P

Patrick Molloy

Option Explicit
Sub SetAutoFilter()
Dim target As Range
Set target = Range("A1:C1")
FilterA target
'turn filter OFF
target.AutoFilter
'TURN FILTER ON
target.AutoFilter
End Sub
Sub FilterA(target As Range)
' turns filter ON with a filter
target.AutoFilter Field:=1, Criteria1:="=*1", Operator:=xlAnd
End Sub
 
B

Brian Bermingham

Thanks Patrick
I got that to work.
It seems a bit complex for what apears to be a simple operation.
Is there not a simple command to reset autofilter?

Thanks

Brian
 
P

Patrick Molloy

it was a demo

you need two lines of code
target.AutoFilter
target.AutoFilter

the first turns off/on and the second reverses it
 
B

Brian Bermingham

Thanks again Patrick

I now have below which does exactly what I was looking for.

Dim target As Range
Set target = Range("A1:AN1")
If ActiveSheet.AutoFilterMode Then
'turn filter OFF if already on
target.AutoFilter
'then TURN FILTER ON to reset
target.AutoFilter
Else
'turn filter On if already off
target.AutoFilter
End If
 
P

Patrick Molloy

we appreciate the feedback. many thanks

Brian Bermingham said:
Thanks again Patrick

I now have below which does exactly what I was looking for.

Dim target As Range
Set target = Range("A1:AN1")
If ActiveSheet.AutoFilterMode Then
'turn filter OFF if already on
target.AutoFilter
'then TURN FILTER ON to reset
target.AutoFilter
Else
'turn filter On if already off
target.AutoFilter
End If
 
C

Charlotte E

But how can I leave the autofilter in place just removing any applied
filter? Some thing like AutoFilter.reset !

One simple quick line :)

ActiveSheet.ShowAllData

That's it :)
 
B

Brian Bermingham

Thanks Charlotte

It's always good to know more than one way to do things.

Brian
 

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

Top