Multiple Filters in Excel

kathleen0927

New Member
Joined
Feb 7, 2018
Messages
32
Hi!

I have an Excel spreadsheet where I have added macros attached to control buttons to filter the 1825 row list based on discipline criteria. See code below for 1 example. I also have a macro that hides rows that have a value in them (to hide rows where the item is closed - "C" in the cell means closed and the code will only allow blanks). My problem is if you chose 1 of the discipline filter first, then select the macro to hide the closed, all rows are hidden. How can I change the "closed" code to filter the list AFTER another filter has been selected?

Sample Discipline Filter Code:
Code:
Sub Construction_Click()

ActiveSheet.Unprotect Password:="OVA"
Range("a12:a1825").AutoFilter Field:=1, Criteria1:="HO"
Range("$e$4").Value = "Filter: Construction"
ActiveSheet.Protect Password:="OVA"
End Sub

Hide Closed Item Filter Code:
Code:
Sub HideClosed_Click()
ActiveSheet.Unprotect Password:="OVA"
Range("d13:d1825").AutoFilter Field:=1, Criteria1:=""
Range("$e$4").Value = "ALL (Active Awards Only)"
ActiveSheet.Protect Password:="OVA"
End Sub
 
Last edited by a moderator:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You can only have 1 autofilter running at a time so try
Code:
Sub Construction_Click()

ActiveSheet.Unprotect Password:="OVA"
Range("a12:d1825").AutoFilter Field:=1, Criteria1:="ba*"
Range("$e$4").Value = "Filter: Construction"
ActiveSheet.Protect Password:="OVA"
End Sub
Sub HideClosed_Click()
ActiveSheet.Unprotect Password:="OVA"
Range("d12:d1825").AutoFilter Field:=4, Criteria1:=""
Range("$e$4").Value = "ALL (Active Awards Only)"
ActiveSheet.Protect Password:="OVA"
End Sub
 
Upvote 0
Thanks. This doesn't help because showing the "Closed" rows needs to be an option. Can I add a Yes/ No message box to the discipline macro that if No is selected the rows will be hidden, or is that the same as having 2 filters?
 
Upvote 0
Surely if you want to hide the "closed" rows you simply click the "HideClosed" button, otherwise don't.
 
Upvote 0
Are you saying that you want either col A or col D filtered, but not both?
 
Upvote 0
I am saying that the end user may want to filter on col A only, or col D only or filter on both. Right now, all I could do is filter one or the other using separate macros. I was hoping that if they filtered on col d, there would be an option to also filter on col a if desired
 
Upvote 0
In that case how about
Code:
Sub Construction_Click()

With ActiveSheet
   .Unprotect Password:="OVA"
   If .AutoFilterMode Then .AutoFilterMode = False
   .Range("a12:d1825").AutoFilter Field:=1, Criteria1:="HO"
   .Range("$e$4").Value = "Filter: Construction"
   If MsgBox("Do you want to filter closed", vbYesNo) = vbYes Then
      .Range("d12:d1825").AutoFilter Field:=4, Criteria1:=""
      .Range("$e$4").Value = "ALL (Active Awards Only)"
   End If
   .Protect Password:="OVA"
End With
   
End Sub
 
Upvote 0
That worked perfectly!!! I kept getting errors at Y/N message. Thank you so much for the extra effort to help me. Have a great day!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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