Home » excel » excel – Search a single cell for multiple words AND return all words found

excel – Search a single cell for multiple words AND return all words found

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have been trying all day to write a formula in Excel that can search a string for multiple keywords and then print which keywords it found in a cell.

I’ve gotten as far as searching for a list of keywords and returning the first keyword found, but I have no earthly idea how to get it to return subsequent matches. Example, complete with formula (pasted below as well):

Apparently I'm not allowed to embed images so this is a link.

=INDEX($C$2:$C$8,MATCH(1,COUNTIF(B2,"*" & $C$2:$C$8 & "*"),0))

All I want is for that A2 cell to contain “cat; mongoose” instead of just “cat”. All the searches I do are coming up with solutions involving returning multiple cells or searching multiple cells. I don’t even know if this is something I can do with this function, because I didn’t know this function existed until three hours ago. I hacked this one together from the directions on this webpage.

And that was great! But now I’m stuck and confused and frustrated. I can’t tell if I need to find a UDF, or if there’s some pre-existing VBA someone, somewhere has written for this, so any help is appreciated!

How to&Answers:

INDEX will only return one value. Use TEXTJOIN as an array formula

=TEXTJOIN("; ",TRUE,IF(ISNUMBER(SEARCH(C$2:$C$8,B2)),C$2:$C$8,""))

Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

TEXTJOIN was introduced with Office 365 Excel. If you do not have Office 365, you will need separate cells for each word returned or vba.