Home How to trigger multiple filters based on multiple conditional statements in VBA Excel?
Reply: 0

How to trigger multiple filters based on multiple conditional statements in VBA Excel?

user1623
1#
user1623 Published in July 21, 2018, 1:45 pm
If Sheets("Sheet1").Range("A14") = True Then _
   Sheets("Sheet2").Range("A1").AutoFilter Field:=1, Criteria1:= "Option1"

If Sheets("Sheet1").Range("A15") = True Then _
   Sheets("Sheet2").Range("A1").AutoFilter Field:=1, Criteria1:= "Option2"

If Sheets("Sheet1").Range("A16") = True Then _
   Sheets("Sheet2").Range("A1").AutoFilter Field:=1, Criteria1:= "Option3"

If Sheets("Sheet1").Range("A17") = True Then _
   Sheets("Sheet2").Range("A1").AutoFilter Field:=1, Criteria1:= "Option4"

Let's say in Sheet1 of Excel, there are 4 Check boxes(Form Control) having some names such as Metric1, Metric2, Metric3 and Metric4.

There are 4 cells in the same sheet let's say A14, A15, A16 and A17 that are associated with the above Check boxes using macro such that Metric1 <-> A14, Metric2 <-> A15, Metric3 <-> A16 and Metric4 <-> A17.

Now if one selects one or more check boxes, the corresponding cells will show TRUE and if the checkbox is unchecked then it will display FALSE.

There is a second sheet Sheet2 and there is a column of Metrics having all the 4 values i.e. Metric1, Metric2, Metric3 and Metric4 respectively. Let's say I have selected check boxes for Metric 1 and Metric 4 in Sheet1. This will change cells A14 and A17 to TRUE. Now, based on those cells that are TRUE, I want to see only Metric 1 and Metric 4 filtered in the Metric column.

How can I write a VBA code for this problem? Please help.

I tried using multiple IF conditions, but the problem is, the filter takes the value of the last If condition.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.387245 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO