How do you check for existence of Autofilter in a Table?

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
If I have an Excel Table, and want to check if Autofilter is applied (to the Table), how do I go about it?

I have tried:

Code:
If Activesheet.ListObjects(1).Autofilter.FilterMode Then ...

which errors out if Autofilter isn't applied.

I have also tried:

Code:
If Activesheet.AutofilterMode Then ...

But this returns False if it is a Table.

I could turn off error reporting to avoid the code bugging out but I assume there is some other way I have missed?

Thanks for any help
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,882
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
If I have an Excel Table, and want to check if Autofilter is applied (to the Table), how do I go about it?

I have tried:

Code:
If Activesheet.ListObjects(1).Autofilter.FilterMode Then ...

which errors out if Autofilter isn't applied.
:confused:

Just going to sleep for the night, but a quick test shows this code works fine for me (XL2010 on Win8.1)...
Code:
Sub Test()
  If ActiveSheet.ListObjects(1).AutoFilter.FilterMode Then
    Debug.Print "Yes"
  Else
    Debug.Print "No"
  End If
End Sub
 
Last edited:

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi Rick

That is definitely bugging out for me (Run time error '91': Object variable or With block variable not set).

I am using Excel 2013 64bit on Windows7.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,782
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Rich,
Do you have the filter arrows visible? If not, you'd get the 91 error, so you'd need:

Code:
Sub Test()
If ActiveSheet.ListObjects(1).ShowAutoFilter
  If ActiveSheet.ListObjects(1).AutoFilter.FilterMode Then
    Debug.Print "Yes"
  Else
    Debug.Print "No"
  End If
Else
   debug.print "No filter available"
End If
End Sub
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707

ADVERTISEMENT

Hi Rory

Perfect - thank you, that was exactly what I needed. Filter arrows weren't visible.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,782
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
No worries. Nice to see you again - been a while!
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,782
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Not too soon - I need to build up some brownie points again first!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,074
Messages
5,835,232
Members
430,349
Latest member
Gregori

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
Top