Check AutoFilter is On or Off in VBA

maatman

Board Regular
Joined
Oct 24, 2007
Messages
69
Hi,

I want to check if there is an AutoFilter on a worksheet or not with the following code:

Dim ReturnValue As AutoFilter
ReturnValue = ActiveSheet.AutoFilter
If ReturnValue Is Nothing Then MsgBox "There is no Filter"
If ReturnValue = ActiveSheet.AutoFilter then MsgBox "There is a Filter"

This code always returns "There is no Filter" even when there is an AutoFilter.
What is wrong?

Regards
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi,

What I want is to detect if there is an AutoFilter. Not if the AutoFilter is in filtering mode or not.

Regards
 
Upvote 0
If ActiveSheet.AutoFilterMode Then
MsgBox "There is a Filter"
Else: MsgBox "There is no Filter"
End If

End Sub
 
Upvote 0
Hi,

Hm... you don't let me down ;-) Thanks!

How can I turn the AutoFilter off so it disappears.

Regards
 
Upvote 0
If ActiveSheet.AutoFilterMode Then
MsgBox "There is a Filter"
Else: MsgBox "There is no Filter"
End If

End Sub

Hello, I am trying this but with mixed success. When I write the VBA code to reference a sheet within the active workbook, the code works. My need is for VBA to open a different workbook and detect if autofilter mode is on in a sheet there. Once I have VBA open that workbook, and goto the specified worksheet, I used the following code:

Worksheets("worksheet").Activate
If ActiveSheet.AutoFilterMode Then
MsgBox "There is a Filter"
Else: MsgBox "There is no Filter"
Selection.AutoFilter
End If

Autofilter is on in the work sheet but the above code is not detecting it. Another piece of information which may or may not have any bearing, is that the sheet is a query output and the range size A1:CU10000. Does this have an impact?
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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