Forum

Notifications
Clear all

Search words in a cell and return all matching words

7 Posts
4 Users
0 Reactions
105 Views
(@niangck)
Posts: 3
Active Member
Topic starter
 

Hi, I saw Search a text string for a list of words but this did not solve my problem in excel for M365.

 

I have a column A with Strings and would like to return all matching words against a List in Column B.

 

For example,

My list is {"Bob","John","Smith"}

Cell A2 has: Bob and John went to dinner.  I want B2 as Bob, John

Cell A3 has: John, Bob and Smith went to dinner: I want B3 as John, Bob, Smith

Cell A4 has: Smith went alone for dinner. I want B4 as Smith

 

If this is not possible, at least the first matching name from the sentence has to be return. So B2 will be Bob, B3 as John and B4 as Smith. 

 

From the Blog, the ROW multiplication is not working and it is always returning sum.

 
Posted : 22/02/2023 10:08 pm
Riny van Eekelen
(@riny)
Posts: 1185
Member Moderator
 

In MS365, that would be:

=TEXTJOIN(", ",,FILTER(names,ISNUMBER(SEARCH(names,A2))))

where "names" is a named range containing the list of names.

The attached file contains an example.

 
Posted : 23/02/2023 2:34 am
(@niangck)
Posts: 3
Active Member
Topic starter
 

Hi Rinv,

Thanks for the reply. The formula worked, thanks. 

How to get the first matched word first rather than first in the array,

 

for example, B3 should be John, Bob, Smith as John is first match.

 
Posted : 23/02/2023 5:58 pm
(@debaser)
Posts: 836
Member Moderator
 

You could use something like:

=LET(counts,SEARCH(names,A2),TEXTJOIN(",",TRUE,CHOOSECOLS(SORT(FILTER(HSTACK(names,counts),ISNUMBER(counts)),2),1)))

 
Posted : 23/02/2023 6:40 pm
(@niangck)
Posts: 3
Active Member
Topic starter
 

Thanks Velouria, it worked.

 
Posted : 25/02/2023 1:51 am
(@mike-g)
Posts: 4
Active Member
 

Yessssss!

This works great for my problem.

Just needs a little more fine tuning.

The only part I need is this.

 

=FILTER(MonthResults,ISNUMBER(SEARCH(Months,A16)))

 

I am using this data (see Attachment ) and need to find exact match. Sometimes an abbreviation or code may be used in the field being searched. With the formula as is it is finding partial matches which is causing issues. I tried quotes around the named range etc. Nothing worked. 

 

Capture-3.PNG

Thanks~

Mike G

 
Posted : 06/03/2023 3:56 pm
(@mike-g)
Posts: 4
Active Member
 

Hello,

Problem solved. Found on another forum.

This was the code that worked for me.

=INDEX(SizeR,MATCH(TRUE,ISNUMBER(SEARCH(Size,A2)),0))

 

Thanks~

Mike G

 
Posted : 06/03/2023 9:23 pm
Share: