Extract multiple specified values from cell and return in 1 cell

Dave87

Board Regular
Joined
Apr 22, 2020
Messages
107
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello everyone,

I need some help on this, in column A i have a list of various fruit, within column C i have sentences which may contain one or more of the fruit listed in Column A.

In column E i would like to list the fruit from column A which is contained in column C.

Also i would like to remove any references to duplicate fruit - see cell E2 which only lists apple once

I'm currently using the following formula but it only returns the first 'fruit' listed in column A and not all the 'fruits' in column C
VBA Code:
{=IFERROR(INDEX($A$2:$A$6,MATCH(TRUE,ISNUMBER(SEARCH($A$2:$A$6,C2)),0)),"")}

Column A
Lookup Items
orange
apple
strawberry
pear
Kiwi

Column C
Within Text
Today I ate 2 apple and 3 orange. I like apple
tomorrow I will juice 1 pear​
this could be blank.​
I need to buy some apple, orange, kiwi and plum

Column E - Required Answer
apple
orange
pear
0
apple
orange
kiwi
plum

I have Excel 2016 and 365/online/onedrive

(work have blocked XL2BB & Google drive so i cant share a document)
 

Attachments

  • Mr Excel Lookup.png
    Mr Excel Lookup.png
    18.7 KB · Views: 18
26Aug19.xlsx
ABCDEF
1Option 1Option 2
2orangeToday I ate 2 apple and 3 orange. I like appleorange appleorange apple
3appletomorrow I will juice 1 pearpearpear
4strawberry  
5pearI need to buy some apple, orange, kiwi and plumorange apple kiwiorange apple kiwi
6kiwiI will buy kiwi pear, apple, kiwi and kiwi and kiwiapple pear kiwiapple pear kiwi
Sheet49
Cell Formulas
RangeFormula
E2:E6E2=IFERROR(TEXTJOIN(CHAR(10),,IF(FREQUENCY(IFERROR(MATCH(TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"."," "),",", " ")," ",REPT(" ",LEN(C2))),(ROW($1:$255)-1)*LEN(C2)+1,LEN(C2))),A$2:A$6,0),""),ROW($1:$255)),A$2:A$6,"")),"")
F2:F6F2=IFERROR(TEXTJOIN(CHAR(10),,IF(FREQUENCY(IFERROR(MATCH(TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"."," "),",", " ")," ",REPT(" ",LEN(C2))),(ROW(INDIRECT("1:"&LEN(C2)-LEN(SUBSTITUTE(C2," ",""))+1))-1)*LEN(C2)+1,LEN(C2))),A$2:A$6,0),""),ROW(INDIRECT("1:"&ROWS(A$2:A$6)))),A$2:A$6,"")),"")
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
26Aug19.xlsx
ABCDEF
1Option 1Option 2
2orangeToday I ate 2 apple and 3 orange. I like appleorange appleorange apple
3appletomorrow I will juice 1 pearpearpear
4strawberry  
5pearI need to buy some apple, orange, kiwi and plumorange apple kiwiorange apple kiwi
6kiwiI will buy kiwi pear, apple, kiwi and kiwi and kiwiapple pear kiwiapple pear kiwi
Sheet49
Cell Formulas
RangeFormula
E2:E6E2=IFERROR(TEXTJOIN(CHAR(10),,IF(FREQUENCY(IFERROR(MATCH(TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"."," "),",", " ")," ",REPT(" ",LEN(C2))),(ROW($1:$255)-1)*LEN(C2)+1,LEN(C2))),A$2:A$6,0),""),ROW($1:$255)),A$2:A$6,"")),"")
F2:F6F2=IFERROR(TEXTJOIN(CHAR(10),,IF(FREQUENCY(IFERROR(MATCH(TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"."," "),",", " ")," ",REPT(" ",LEN(C2))),(ROW(INDIRECT("1:"&LEN(C2)-LEN(SUBSTITUTE(C2," ",""))+1))-1)*LEN(C2)+1,LEN(C2))),A$2:A$6,0),""),ROW(INDIRECT("1:"&ROWS(A$2:A$6)))),A$2:A$6,"")),"")
Press CTRL+SHIFT+ENTER to enter array formulas.

This is a solution using formulas. Presume that each sub-string within a column C cell is separated by a space or comma or a dot.
 
Upvote 0
This is a solution using formulas. Presume that each sub-string within a column C cell is separated by a space or comma or a dot.
With the same assumptions & sample data ..

Dave87 2020-07-02 1.xlsm
ABCDE
1Option 3
2orangeToday I ate 2 apple and 3 orange. I like appleorange apple
3appletomorrow I will juice 1 pearpear
4strawberry 
5pearI need to buy some apple, orange, kiwi and plumorange apple kiwi
6kiwiI will buy kiwi pear, apple, kiwi and kiwi and kiwiapple pear kiwi
List Fruit (3)
Cell Formulas
RangeFormula
E2:E6E2=TEXTJOIN(CHAR(10),1,FILTER(A$2:A$6,ISNUMBER(SEARCH(" "&A$2:A$6&" ",SUBSTITUTE(SUBSTITUTE(" "&C2&" ","."," "),","," "))),""))
 
Upvote 0
With the same assumptions & sample data ..

Dave87 2020-07-02 1.xlsm
ABCDE
1Option 3
2orangeToday I ate 2 apple and 3 orange. I like appleorange apple
3appletomorrow I will juice 1 pearpear
4strawberry 
5pearI need to buy some apple, orange, kiwi and plumorange apple kiwi
6kiwiI will buy kiwi pear, apple, kiwi and kiwi and kiwiapple pear kiwi
List Fruit (3)
Cell Formulas
RangeFormula
E2:E6E2=TEXTJOIN(CHAR(10),1,FILTER(A$2:A$6,ISNUMBER(SEARCH(" "&A$2:A$6&" ",SUBSTITUTE(SUBSTITUTE(" "&C2&" ","."," "),","," "))),""))

In my office 365 version (and many others) the new functions are still not available ... hopefully this month we should get them.
 
Upvote 0
In my office 365 version (and many others) the new functions are still not available ... hopefully this month we should get them.
Without using any of these functions we can also use below Array formula (Ctrl+Shift+Enter):

=TEXTJOIN(CHAR(10),,IF(ISNUMBER(SEARCH(" "&A$2:A$6&" "," " &SUBSTITUTE(SUBSTITUTE(C2,"."," "),",", " ")&" ")),A$2:A$6,""))
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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