# Search a string for multiple key words

#### sahrens1

##### New Member
Simple question, that I cannot seem too find. Can anyone help me?

I would like a formula that searches a cell with a sentence for specific keywords. 10 max. If the keyword is found, then it would put the keyword in the cell.

So the cell to be searched would be G6
Keywords would be Theft, harassment, Police, Vandalism and "" (blank)

If those keywords were found, it would put in in the formula cell g7.

Any help?

#### Scott Huish

##### MrExcel MVP
Here's a UDF that will do that:
Code:
``````Function KeywordFIND(r As String) As String
Dim x, y As Long
x = Array("Theft", "Harassment", "Police", "Vandalism")
For y = LBound(x) To UBound(x)
If InStr(1, r, x(y), vbTextCompare) Then KeywordFIND = KeywordFIND & x(y) & " "
Next
If Len(KeywordFIND) Then KeywordFIND = Left(KeywordFIND, Len(KeywordFIND) - 1)
End Function``````

#### Jonmo1

##### MrExcel MVP
Try

=IFERROR(LOOKUP(2^15,SEARCH(\$D\$1:\$D\$4,\$G6),\$D\$1:\$D\$4),"")

D1:D4 is your list of keywords

IMPORTANT: There cannot be any blanks in D1:D4.

Last edited:

Thanks!

You're welcome.

#### Scott Huish

##### MrExcel MVP
I had interpreted it that there could be multiple keywords in the phrase and thus multiple results.

1,082,316
Messages
5,364,497
Members
400,802
Latest member
RichBRich

### This Week's Hot Topics

• populate from drop list with multiple tables
Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
• Find list of words from sheet2 in sheet1 before a comma and extract text vba
Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
• Dynamic Formula entry - VBA code sought
Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...