Formula to search for words in a cell from a list

sobrien1234

Board Regular
Joined
May 10, 2016
Messages
175
Office Version
  1. 365
Platform
  1. Windows
I need a formula in column B to identify if words in columns A are identified in C2:
For example:
In column A I have a list of words
In C2 I have a sentence
In column B I have a formula which identifies if any of the words in column A are identified in the text in C2
Not sure if I need to have a space or not after the commas for the words in Column A?
1622598064122.png


Thanks

Seamus
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I don't think that you will be able to do it unless the words in the A cell are in an individual cell/list. If you had them hidden with each word in a different cell then you could use a formula similar to: =IF(OR(C1=D1,C1=D2,C1=D3......), "Yes", "No")

It would be as simple as text to columns and removing the comma......
 
Upvote 0
I don't think that you will be able to do it unless the words in the A cell are in an individual cell/list. If you had them hidden with each word in a different cell then you could use a formula similar to: =IF(OR(C1=D1,C1=D2,C1=D3......), "Yes", "No")

It would be as simple as text to columns and removing the comma......
No worries - I thought as much. Can still do it just take a little longer
 
Upvote 0
I suggest that you investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.

See if this does what you want.

Not sure if I need to have a space or not after the commas for the words in Column A?
I have assumed there is a space after each comma but the formula could be adjusted if that is not the case.
If there could be any punctuation in C2, then this approach could be problematic.

21 06 02.xlsm
ABC
1
2Cat, cat, CAT, Kat, Kat, katYesThere is a kat and a pig in the room
3Dog, DOG, DoggNo
4Pig, pig, PIG, piggYes
Check words
Cell Formulas
RangeFormula
B2:B4B2=IF(COUNT(FIND(" "&FILTERXML("<p><c>"&SUBSTITUTE(C$2," ","</c><c>")&"</c></p>","//c")&","," "&A2&",")),"Yes","No")
 
Upvote 0
I suggest that you investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.

See if this does what you want.


I have assumed there is a space after each comma but the formula could be adjusted if that is not the case.
If there could be any punctuation in C2, then this approach could be problematic.

21 06 02.xlsm
ABC
1
2Cat, cat, CAT, Kat, Kat, katYesThere is a kat and a pig in the room
3Dog, DOG, DoggNo
4Pig, pig, PIG, piggYes
Check words
Cell Formulas
RangeFormula
B2:B4B2=IF(COUNT(FIND(" "&FILTERXML("<p><c>"&SUBSTITUTE(C$2," ","</c><c>")&"</c></p>","//c")&","," "&A2&",")),"Yes","No")
Awesome!!!!!
 
Upvote 0
Awesome!!!!!
Glad it helped. :)

I take it from your sample that if column A had "Cat, cat, CAT, Kat, Kat, kat" and column C had "A Fat cAt" that you would want "No" returned because you want the search to be case-sensitive?
 
Upvote 0
Glad it helped. :)

I take it from your sample that if column A had "Cat, cat, CAT, Kat, Kat, kat" and column C had "A Fat cAt" that you would want "No" returned because you want the search to be case-sensitive?
This is really amazing Peter. That said, It doesn't need to be case sensitive - in fact I would prefer it isn't? Also it didn't work if there was a character attached to the text (see below there the / and the . appear to affect it (i.e. LRBA should answer "Yes"). Be great if you could solve this!!
1622876422529.png
 
Upvote 0
It doesn't need to be case sensitive - in fact I would prefer it isn't
Excel Formula:
We could deal with that issue easily, but consider the issue below first.

Also it didn't work if there was a character attached to the text (see below there the / and the .
I mentioned that issue already. ;)
If there could be any punctuation in C2, then this approach could be problematic.
If you are looking for "words" in the column C text, then there has to be some way to determine where a "word" begins and ends. If you don't have that and you are looking for "apple" you find it in "pineapples" for example. The normal way that an Excel formula will determine where words start and end is that they occur between space characters (or the start/end of the sentence) and that is what my formula does. So in your latest example "LRBA/borrowing" would be a "word", not two.

If there was very limited punctuation characters (so far we have seen just two "/" and ".") then we could still do this with a formula. If there were many more, again it becomes problematic and vba might be better suited. So what about question mark, quote marks (single or double), exclamation mark, parentheses, asterisk etc? Another one that can be tricky is a hyphen. For example, is "semi-annual" one word or two? Is "Ted Hills-Smith" two words or three? etc

So, if only "/" and "." try this

Excel Formula:
=IF(COUNT(SEARCH(" "&FILTERXML("<p><c>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C$2,"/"," "),"."," ")," ","</c><c>")&"</c></p>","//c")&","," "&A2&",")),"Yes","No")
 
Upvote 0
This is really amazing Peter. That said, It doesn't need to be case sensitive - in fact I would prefer it isn't? Also it didn't work if there was a character attached to the text (see below there the / and the . appear to affect it (i.e. LRBA should answer "Yes"). Be great if you could solve this!!
View attachment 40106
I also tried adding those words with the characters and didn't work
1622878677138.png

We could deal with that issue easily, but consider the issue below first.


I mentioned that issue already. ;)

If you are looking for "words" in the column C text, then there has to be some way to determine where a "word" begins and ends. If you don't have that and you are looking for "apple" you find it in "pineapples" for example. The normal way that an Excel formula will determine where words start and end is that they occur between space characters (or the start/end of the sentence) and that is what my formula does. So in your latest example "LRBA/borrowing" would be a "word", not two.

If there was very limited punctuation characters (so far we have seen just two "/" and ".") then we could still do this with a formula. If there were many more, again it becomes problematic and vba might be better suited. So what about question mark, quote marks (single or double), exclamation mark, parentheses, asterisk etc? Another one that can be tricky is a hyphen. For example, is "semi-annual" one word or two? Is "Ted Hills-Smith" two words or three? etc

So, if only "/" and "." try this

Excel Formula:
=IF(COUNT(SEARCH(" "&FILTERXML("<p><c>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C$2,"/"," "),"."," ")," ","</c><c>")&"</c></p>","//c")&","," "&A2&",")),"Yes","No")
Thanks Peter. I really appreciate this. I can see your point about the punctuation characters and may need to add more in the future. I have 2 more questions:
1. Can you show me the formula with a "?" also added to the punctuation so I can see the difference between the above formula and the new one - then I can add additional characters if I need to?
2. The formula didn't appear to work for the second set of text where there was a . at the end?
1622935257078.png
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top