Auto filter on a command button

Craig1

Active Member
Joined
Jun 11, 2009
Messages
322
Hi All,
I use command buttons quite a lot and like them for the workbooks I use.
I have about 20 command buttons on a new sheet I have set up but I keep getting a problem that I need help with.
The issue I have is all the auto filters work fine using the command button except when I filter a certain range and nothing is in that range that is still "In progress" so the rows stay empty. All this is fine until I come to filter the next range, it looks like that because the screen is empty (below the auto filter line) the next filter won't work. So I need to know if I am missing something. When the screen is populated there are no issues.

A standard auto filter for the command button is below.

Any help would be appreciated.

Private Sub CommandButton5_Click()
On Error GoTo Err_Handler

Selection.AutoFilter Field:=12, Criteria1:="Powder", Operator:=xlAnd
Selection.AutoFilter Field:=13, Criteria1:="In progress", Operator:=xlAnd

Exit Sub
Err_Handler:
If Err.Number = 1004 Then
Resume Next
Else
MsgBox Err.Number & ": " & Err.Description
End If
End Sub

Thanks again.
Craig
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I don't understand what the problem is. Can you explain it again differently? Be specific with what the actual problem with the current code is.
 
Upvote 0
Thanks for the reply Peter.
The problem is when auto filter is first turned on and nothing is actually filtered the above code works fine. But if I filter another range and find there is nothing in that range, basically the page is empty. So when I try to filter using the code above again it doesn't seem to work and the cells stay blank.


Thanks again.
Craig.
 
Upvote 0
I'm still not certain I understand the problem but try adding this just before the autofilter part of your existing code.
Code:
With ActiveSheet
    If .FilterMode Then .ShowAllData
End With
 
Upvote 0
Thanks for that Peter is worked a treat. For some reason it the auto filter wouldn't work until it saw something in the columns, now using the ShowAllData seems to work fine.

Craig
 
Upvote 0
Thanks for that Peter is worked a treat. For some reason it the auto filter wouldn't work until it saw something in the columns, now using the ShowAllData seems to work fine.

Craig
The autofilter was working, but applying an autofilter to a column, as your code was doing, doesn't remove existing filters from other columns.
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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