Filter/Unfilter using a single command button

LoriD

Board Regular
Joined
Apr 1, 2002
Messages
148
I have a macro that filters data at the click of a command button. Is there a way for Excel to know when my list is filtered, so if I click the button again, it will un-filter my list?

Thanks in advance!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
On 2002-10-04 15:46, LoriD wrote:
I have a macro that filters data at the click of a command button. Is there a way for Excel to know when my list is filtered, so if I click the button again, it will un-filter my list?

Thanks in advance!

Hi Lori,

To check if autofilter is on:
If Worksheets("Sheet1").AutoFilterMode Then MsgBox "AutoFilterMode is on"

To remove autofilter
If Worksheets("Sheet1").AutoFilterMode then Worksheets("Sheet1").AutoFilterMode = False
 
Upvote 0
I should have said before - the macro I have runs an advanced filter.

Can clicking the same button make Excel see if the list is filtered, and if so, un-filter it?
And - if the list is NOT filtered, it should still run the original macro to filter the list.

Thanks.
 
Upvote 0
On 2002-10-04 16:34, LoriD wrote:
I should have said before - the macro I have runs an advanced filter.

Can clicking the same button make Excel see if the list is filtered, and if so, un-filter it?
And - if the list is NOT filtered, it should still run the original macro to filter the list.

Thanks.

You can asign only 1 macro to a button, so the check and the setup of the filter has to be done in the same macro:

<pre>
Sub Filter()
If Worksheets("Sheet1").FilterMode Then
'disable filter
Worksheets("Sheet1").ShowAllData
Else
'setup the filter here
End If
End Sub
</pre>
 
Upvote 0

Forum statistics

Threads
1,224,881
Messages
6,181,539
Members
453,054
Latest member
ezzat

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