check existence of autofilter, turn off autofilter

Rowland Hamilton

Active Member
Joined
Nov 13, 2009
Messages
250
Folks:

Why can't I get any of these codes to work (I'm using Excel 2010)?:

Code:
Sub AutoFilOff()
    If ActiveProject.AutoFilter = True Then
        ActiveProject.AutoFilter = False
    End If
End Sub
Or this one?
Code:
Sub AutoFltrTgl()
ActiveProject.AutoFilter = Not ActiveProject.AutoFilter
End sub
Great if they worked because they are simple and it doesn't matter where the filter is in the worksheet.

Doesn't like "activeProject" but didn't work with "Active.Sheets" either

Now this did work, but how can I modify it to then turn off the filter? And why is it so much longer than the other ones?:

Code:
Sub Check_AutoFilter_IsPresent()
'Check if Sheet has AutoFilter
'Check if filter was applied to any column

Dim oWS As Worksheet ' Worksheet Object

On Error GoTo Disp_Error
 
oWS = ActiveSheet

If Not oWS.AutoFilter Is Nothing Then
If oWS.FilterMode = True Then
MsgBox ("Auto Filter On: Filter Mode On")
Else
MsgBox ("Auto Filter On: Filter Mode Off")
End If
Else
MsgBox ("Auto Filter Off")
End If

If Not oWS Is Nothing Then oWS = Nothing

' --------------------
' Error Handling
' --------------------
Disp_Error:
If Err <> 0 Then
MsgBox Err.Number & " - " & Err.Description, vbExclamation, "ERROR MESSAGE"
Resume Next
End If

End Sub
Thank you - Rowland
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Thanks Tom:

I discovered that when I modified the following code I found on line (made the parts I didn't need text:

Code:
Sub Autofilter_example_50()
Dim ws As Worksheet
With Sheets("Data")
.AutoFilterMode = False
'.Cells.AutoFilter Field:=4, _
'Criteria1:=Sheets("Claims").Range("G2").Text
'.Cells.AutoFilter Field:=6, _
'Criteria1:=Sheets("Claims").Range("G3").Text
'Set ws = Worksheets.Add(Before:=Sheets("Data"))
'.UsedRange.Copy ws.Range("A1")
'.AutoFilterMode = False
End With
'Set ws = Nothing
End Sub
Rowland
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top