Explanation
In this example, the goal is to test the passwords in column B to see if they contain a number. This is a surprisingly tricky problem because Excel doesn’t have a function that will let you test for a number inside a text string directly. Note this is different from checking if a cell value is a number . You can easily perform that test with the ISNUMBER function . In this case, however, we to test if a cell value contains a number, which may occur anywhere. One solution is to use the FIND function with an array constant. In Excel 365 , which supports dynamic array formulas , you can use a different formula based on the SEQUENCE function. Both approaches are explained below.
FIND function
The FIND function is designed to look inside a text string for a specific substring. If FIND finds the substring, it returns a position of the substring in the text as a number. If the substring is not found, FIND returns a #VALUE error. For example:
=FIND("p","apple") // returns 2
=FIND("z","apple") // returns #VALUE!
We can use this same idea to check for numbers as well:
=FIND(3,"app637") // returns 5
=FIND(9,"app637") // returns #VALUE!
The challenge in this case is that we need to check the values in column B for ten different numbers, 0-9. One way to do that is to supply these numbers as the array constant {0,1,2,3,4,5,6,7,8,9}. This is the approach taken in the formula in cell D5:
=COUNT(FIND({0,1,2,3,4,5,6,7,8,9},B5))>0
Inside the COUNT function, the FIND function is configured to look for all ten numbers in cell B5:
FIND({0,1,2,3,4,5,6,7,8,9},B5)
Because we are giving FIND ten values to look for, it returns an array with 10 results. In other words, FIND checks the text in B5 for each number and returns all results at once:
{#VALUE!,4,5,6,#VALUE!,#VALUE!,#VALUE!,#VALUE!,#VALUE!,#VALUE!}
Unless you look at arrays often, this may look pretty cryptic. Here is the translation: The number 1 was found at position 4, the number 2 was found at position 5, and the number 3 was found at position 6. All other numbers were not found and returned #VALUE errors.
We are very close now to a final formula. We simply need to tally up results. To do this, we nest the FIND formula above inside the COUNT function like this:
=COUNT(FIND({0,1,2,3,4,5,6,7,8,9},B5))
FIND returns the array of results directly to COUNT, which counts the numbers in the array. COUNT only counts numeric values, and ignores errors. This means COUNT will return a number greater than zero if there are any numbers in the value being tested. In the case of cell B5, COUNT returns 3.
The last step is to check the result from COUNT and force a TRUE or FALSE result. We do this by adding “>0” to the end of formula:
=COUNT(FIND({0,1,2,3,4,5,6,7,8,9},B5))>0
Now the formula will return TRUE or FALSE. To display a custom result, you can use the IF function :
=IF(COUNT(FIND({0,1,2,3,4,5,6,7,8,9},B5))>0, "Yes", "No")
The original formula is now nested inside IF as the logical_test argument . This formula will return “Yes” if B5 contains a number and “No” if not.
SEQUENCE function
In Excel 365, which offers dynamic array formulas , we can take a different approach to this problem.
=COUNT(--MID(B5,SEQUENCE(LEN(B5)),1))>0
This isn’t necessarily a better approach, just a different way to solve the same problem. At the core, this formula uses the MID function together with the SEQUENCE function to split the text in cell B5 into an array:
MID(B5,SEQUENCE(LEN(B5)),1)
Working from the inside out, the LEN function returns the length of the text in cell B5:
LEN(B5) // returns 6
This number is returned to the SEQUENCE function as the rows argument, and SEQUENCE returns an array of numbers, 1-6:
=SEQUENCE(LEN(B5))
=SEQUENCE(6)
={1;2;3;4;5;6}
This array is returned to the MID function as the start_num argument, and, with num_chars set to 1, the MID function returns an array that contains the characters in cell B5:
=MID(B5,{1;2;3;4;5;6},1)
={"a";"b";"c";"1";"2";"3"}
We can now simplify the original formula to:
=COUNT(--{"a";"b";"c";"1";"2";"3"})>0
We use the double-negative (–) to get Excel to try and coerce the values in the array into numbers. The result looks like this:
=COUNT({#VALUE!;#VALUE!;#VALUE!;1;2;3})>0
The math operation created by the double negative (–) returns an actual number when successful and a #VALUE! error when the operation fails. The COUNT function counts the numbers, ignoring any errors, and returns 3. As above, we check the final count with “>0”, and the result for cell B5 is TRUE.
Note: as you might guess, you can easily adapt this formula to count numbers in a text string .
Cell equals number?
Note that the formulas above are too complex if you only want to test if a cell equals a number. In that case, you can simply use the ISNUMBER function like this:
=ISNUMBER(A1)
Explanation
The goal of this example is to test each cell in B5:B14 to see if it contains any of the strings in the named range things (E5:E7). These strings can appear anywhere in the cell, so this is a literal “contains” problem. The formula in C5, copied down, is:
=SUMPRODUCT(--ISNUMBER(SEARCH(things,B5)))>0
This formula is based on another formula that checks a cell for a single substring. If the cell contains the substring, the formula returns TRUE. If not, the formula returns FALSE:
ISNUMBER(SEARCH(substring,B5)) // test for substring
When the SEARCH function finds a string, it returns the position of that string as a number. If SEARCH doesn’t find a string, it returns a #VALUE! error. This means ISNUMBER will return TRUE if there is a match and FALSE if not.
In this example, the goal is to check for more than one string, so we are giving the SEARCH function a list of strings in the named range things . Since there are 3 strings in things (“red”, “green”, and “blue”), SEARCH returns 3 results in an array like this:
{#VALUE!;#VALUE!;23}
Because “red” and “blue” aren’t found , the SEARCH returns a #VALUE! error. However, because “green” appears near the end of the text in cell B5, SEARCH returns 23 (i.e. “green” begins at the 23rd character).
This array is returned directly to the ISNUMBER function , which converts the items in the array to either TRUE or FALSE:
ISNUMBER({#VALUE!;#VALUE!;23}) // returns {FALSE;FALSE;TRUE}
Logically, if we have even one TRUE in the array, we know a cell contains at least one of the strings we’re looking for. The easiest way to check for TRUE is to add all values together. We can do that with the SUMPRODUCT function , but first we need to coerce the TRUE / FALSE values to 1s and 0s with a double negative (–) like this:
--{FALSE;FALSE;TRUE} // coerce to 1s and 0s
This yields a new array containing only 1s and 0s:
{0;0;1}
which is delivered directly to SUMPRODUCT:
=SUMPRODUCT({0;0;1}) // returns 1
With just one array to process, SUMPRODUCT sums the items in the array and returns a result. Any non-zero result means we have a “hit”, so we add >0 to force a final result of TRUE or FALSE:
=SUMPRODUCT({0;0;1})>0 // returns TRUE
Note that any combination of matches will return a number greater than zero and cause the formula to return TRUE.
With a hard-coded list
It’s not necessary to use a range for the list of strings to look for. You can also use an array constant . For example, to check for “red”, “blue”, or “green”, you can use a formula like this:
=SUMPRODUCT(--ISNUMBER(SEARCH({"red","blue","green"},B5)))>0
SUM function
Historically, SUMPRODUCT often appears in array formulas , because it can handle arrays natively, without control + shift + enter . This makes the formula “more friendly” to most users. In Excel 365 , which handles arrays natively , the SUM function can be used instead of SUMPRODUCT without control + shift + enter:
=SUM(--ISNUMBER(SEARCH(things,A1)))>0
Preventing false matches
One problem with this approach is you may get false matches from substrings that appear inside longer words. For example, if you try to match “dr” you may also find “Andrea”, “drink”, “dry”, etc. since “dr” appears inside these words. This happens because SEARCH automatically does a “contains” match. For a quick hack, you can add space around the search words (i.e. " dr “, or “dr “) to avoid catching “dr” in another word. But this will fail if “dr” appears first or last in a cell, or appears with punctuation. If you need a more accurate solution, one option is to normalize the text first in a helper column , taking care to also add a leading and trailing space. Then you use the formula on this page on the resulting text.
Note: in the latest version of Excel, the TEXTSPLIT function provides a better way to search for specific words without catching unrelated substrings.