Reputation: 431
I have a table of filter criteria like this:
+----------+----------+------+------+------+ | Category | SpecName | Spec | Pass | Fail | +----------+----------+------+------+------+ | A | S1 | 3 | | | | A | S2 | 4 | | | | B | S1 | 5 | | | | C | S1 | 2 | | | +----------+----------+------+------+------+
I have a table I want to apply the filter criteria to like this:
+----------+----+----+ | Category | S1 | S2 | +----------+----+----+ | A | 5 | 3 | | B | 4 | | | A | 5 | 5 | | C | 2 | | | A | 2 | 6 | +----------+----+----+
I want to fill the Pass and Fail columns in the filter criteria table with a count of items in second table with values >= the corresponding spec, like so.
+----------+----------+------+------+------+ | Category | SpecName | Spec | Pass | Fail | +----------+----------+------+------+------+ | A | S1 | 3 | 1 | 2 | | A | S2 | 4 | 1 | 2 | | B | S1 | 5 | 0 | 1 | | C | S1 | 2 | 1 | 0 | +----------+----------+------+------+------+
Here are steps for how I might do it in a scripting language:
+----------+----------+------+ | Category | SpecName | Spec | +----------+----------+------+ | A | S1 | 3 | | A | S2 | 4 | +----------+----------+------+
+----------+----+----+ | Category | S1 | S2 | +----------+----+----+ | A | 5 | 3 | | B | 4 | | | A | 5 | 5 | | C | 2 | | | A | 2 | 6 | +----------+----+----+
+----------+----+----+ | Category | S1 | S2 | +----------+----+----+ | A | 5 | 5 | +----------+----+----+
Is this possible with Excel formulas?
If not, does anyone know how to do it with VBA?
Upvotes: 0
Views: 140
Reputation: 9874
Looking at an alternative layout for you spec criteria. Expand you columns to suit your need.
With each spec criteria being its own column life gets really easy. You just need to adjust your formula to match the number of criteria you have.
Based on the table at the end for layout, place the following formula in D3 and copy down as required.
=SUMPRODUCT(($G$2:$G$6=A3)*($H$2:$H$6>=B3)*($I$2:$I$6>=C3))
That will give you a count of passing all criteria. Its also a function that performs array like calcs. It could be repeated in the next column but in order to reduce dependency on array calculation and potentially speed things up depending on the amount of data to check, place the following in the top of the fail column and copy down as required:
=COUNTIF($G$2:$G$6,A3)-D3
Basically it subtracts the passes from the total count. This assumes you can only have PASS and FAIL as options.
Upvotes: 1