In this example, the goal is to filter the values in one array by the values in another array. For convenience, data (B4:D11) and filter (F4:F6) are named ranges. The solution is based on the MATCH function with the ISNUMBER function. This is a pattern you will see often in more advanced formulas. The formula in cell H5 is:
- The MATCH function checks all values in the named range data against values in filter
- ISNUMBER converts matched values to TRUE and non-matched values to FALSE
- The IF function uses the output in #2 above to perform the actual filtering.
The array returned by the IF function looks like this:
As you can see, the values in data that match the values in filter have survived. The values that don't match however have been replaced by FALSE.
The COUNT function is only used to verify the result. Because COUNT automatically ignores the logical values TRUE and FALSE, it returns a count of numbers only, which represent matched values.
Filter to exclude
You can easily reverse the logic to exclude values that appear in filter. In cell H6, the formula has been modified to exclude values using 1-ISNUMBER like so:
This effectively reverses the array output in step #2 above.