Where data is the named range B5:B15. The result is a case-sensitive count of each substring listed in column D. The FIND function is always case-sensitive and takes three arguments: find_text, within_text, and start_num. Find_text is the text we want to look for, and within_text is the text we are looking inside of. Start_num is the position at which to start looking in find_text. Start_num defaults to 1, so we aren’t providing a value in this case, because we always want FIND to start at the first character. When find_text is found inside within_text, FIND returns the position of the found text as a number: When find_text is not found, FIND returns the #VALUE! error: This means we can use the ISNUMBER function to convert the result from FIND into a TRUE and FALSE value. Any number will result in TRUE, and any error will result in FALSE: This idea is explained in more detail here. In the example shown, we have four substrings in column D and a variety of codes in B5:B15, which is the named range data. We want to count how many times each substring in D5:D8 appears in B5:B15, and this count needs to be case-sensitive. The formula in E5, copied down, is: Working from the inside-out, the FIND function is used to look for a substring like this: FIND checks for the value in D5 (“ABC”) in all cells in the data. Because we give FIND multiple values in the within_text argument, it returns multiple results. In total, FIND returns 11 values (one for each code in B5:B15) in an array like this: Each number represents a cell in B5:B15 that contains “ABC”. Each #VALUE! represents a value in B5:B15 that does not contain “ABC”. Looking more closely, we can see that FIND found “ABC” in 4 cells out of 11. This array is returned directly to the ISNUMBER function which converts each value to TRUE or FALSE: ISNUMBER returns an array of 11 TRUE and FALSE values: Because we want to count results, we use a double-negative (–) to convert TRUE and FALSE values into 1’s and 0’s: The resulting array looks like this: Using the double-negative like this is an example of Boolean logic, a technique for handling TRUE and FALSE values like 1’s and 0’s. The resulting array is delivered directly to the SUMPRODUCT function: With just one array to process, SUMPRODUCT sums all numbers in the array and returns the final result: 4. As the formula is copied down, it returns a count of each substring in column D. The reference to data does not change, because a named range automatically behaves like an absolute reference. Note: Because SUMPRODUCT can handle arrays natively, it’s not necessary to use Control+Shift+Enter to enter this formula.
Dave Bruns
Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.