Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel: Search for a list of strings within a particular string using array formulas?

I want to search a cell for a list of words. I thought this would work as an array formula:

{=FIND(<list of words I want to search for>,<cell I want to search>)}

But it only finds a match when a word that's in the cell I'm searching sits in the first row of the list of words I'm searching for. Is there any way to write a formula that looks through the entire list? And I'd prefer if it didn't just return TRUE/FALSE. I know how to search cell for a list of words and return TRUE/FALSE based on whether or not a word in the list exists in the cell. I want to actually know which word was found, or its position.

like image 503
John Thompson Avatar asked Nov 29 '11 16:11

John Thompson


People also ask

How do I search for text in an array in Excel?

I entered this test formula in cell B1. This formula needs to be array-entered, so press Ctrl + Shift + Enter. There are wildcard characters before and after the cell references to D1:D3, so the text will be found anywhere within the text string.

How do you find a string within a string in Excel?

The FIND function in Excel is used to return the position of a specific character or substring within a text string. The first 2 arguments are required, the last one is optional. Find_text - the character or substring you want to find. Within_text - the text string to be searched within.

How do you use an array search function in Excel?

The array form of LOOKUP looks in the first row or column of an array for the specified value and returns a value from the same position in the last row or column of the array. Use this form of LOOKUP when the values that you want to match are in the first row or column of the array.

How do I search multiple strings in Excel?

At the core, this formula uses the SEARCH function to look for multiple strings inside a cell. Inside the left SUMPRODUCT, SEARCH looks for all strings in the named range "include". In the right SUMPRODUCT, SEARCH looks for all strings in the named...


2 Answers

This will return the matching word or an error if no match is found. For this example I used the following.

List of words to search for: G1:G7
Cell to search in: A1

=INDEX(G1:G7,MAX(IF(ISERROR(FIND(G1:G7,A1)),-1,1)*(ROW(G1:G7)-ROW(G1)+1)))

Enter as an array formula by pressing Ctrl+Shift+Enter.

This formula works by first looking through the list of words to find matches, then recording the position of the word in the list as a positive value if it is found or as a negative value if it is not found. The largest value from this array is the position of the found word in the list. If no word is found, a negative value is passed into the INDEX() function, throwing an error.

To return the row number of a matching word, you can use the following:

=MAX(IF(ISERROR(FIND(G1:G7,A1)),-1,1)*ROW(G1:G7))

This also must be entered as an array formula by pressing Ctrl+Shift+Enter. It will return -1 if no match is found.

like image 169
Excellll Avatar answered Oct 17 '22 06:10

Excellll


Adding this answer for people like me for whom a TRUE/FALSE answer is perfectly acceptable

OR(IF(ISNUMBER(SEARCH($G$1:$G$7,A1)),TRUE,FALSE))

or case-sensitive

OR(IF(ISNUMBER(FIND($G$1:$G$7,A1)),TRUE,FALSE))

Where the range for the search terms is G1:G7

Remember to press CTRL+SHIFT+ENTER

like image 41
Some_Guy Avatar answered Oct 17 '22 08:10

Some_Guy