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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,981
Office Version
  1. 2016
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
36,756
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
36,756
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
36,756
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,130,342
Messages
5,641,592
Members
417,224
Latest member
llama9207

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