This idea isn’t going to work as-is.

A much simpler, cleaner approach is to use an array formula based on the SUMPRODUCT function.

Solution with SUMPRODUCT

TheSUMPRODUCT functionmultiplies ranges or arrays together and returns the sum of products.

Excel formula: Cell contains one of many things

It works nicely in this case because it can handle arrays natively in any version of Excel.

Working from the inside out, the expression B5=things returns five values, as explained above.

SUMPRODUCT is designed to process numeric values, and it will simply ignore TRUE and FALSE values.

Excel formula: Get first match cell contains

Now you might see where we are headed.

Since the array contains only numbers, SUMPRODUCT will return a sum.

Excel formula: Cell contains specific text

Excel formula: Value exists in a range

Excel formula: Get all matches cell contains

Excel SUMPRODUCT function

Excel TRIM function