SOLVED

Excel formula - returning multiple text strings in a cell

%3CLINGO-SUB%20id%3D%22lingo-sub-1445489%22%20slang%3D%22en-US%22%3EExcel%20formula%20-%20returning%20multiple%20text%20strings%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1445489%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20Newbie%20here.%20Is%20have%20a%20cell%20that%20could%20contain%20apples%20and%2For%20oranges%20and%2For%20pears.%20I'm%20able%20to%20use%20an%20IF%20formula%20to%20extract%20either%20apples%20or%20oranges%20or%20pears%20but%20get%20a%20false%20value%20when%20the%20cell%20contains%20'apples%20and%20oranges'.%20Is%20there%20a%20way%20to%20extract%20such%20a%20combination%20out%20of%20a%20cell%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1445489%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1445530%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20-%20returning%20multiple%20text%20strings%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1445530%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F691078%22%20target%3D%22_blank%22%3E%40moncho47%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20you%20post%20a%20representative%20spreadsheet%20that%20illustrates%20what%20you're%20describing.%20One%20that%20works%20on%20the%20one%20hand%2C%20but%20not%20on%20the%20other.%20It's%20hard%20to%20diagnose%20without%20actually%20seeing%20and%20experiencing%20the%20reality%2C%20no%20matter%20how%20clear%20your%20description%20is%20(and%20it's%20pretty%20good)...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20do%20realize%20that%20your%20apples%20and%20oranges%20is%20meant%20as%20an%20example%2C%20but%20I'm%20having%20a%20hard%20time%20visualizing%20why%20you%20can%20make%20the%20one%20condition%20work%2C%20but%20not%20the%20other.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1445536%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20-%20returning%20multiple%20text%20strings%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1445536%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F691078%22%20target%3D%22_blank%22%3E%40moncho47%3C%2FA%3E%26nbsp%3BIf%20you%20do%20not%20care%20for%20the%20exact%20order%20of%20occurrence%20of%20the%20found%20texts%20in%20the%20cell%2C%20the%20attached%20workbook%20may%20return%20the%20results%20you%20want%20(use%20the%20formula%20in%20the%20last%20column%2C%20assuming%20that%20you%20have%20a%20list%20of%20your%20search%20texts%20in%20cell%20D1%2C%20E1%2C%20F1).%20It%20is%20always%20better%20to%20have%20the%20search%20texts%20listed%20and%20use%20reference%20in%20the%20formula%20to%20those%20cells%20rather%20than%20hardcoded.%20You%20can%20always%20expand%20the%20list%20of%20your%20search%20texts%20and%20simply%20add%20more%20components%20to%20the%20formula.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1445568%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20-%20returning%20multiple%20text%20strings%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1445568%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F425987%22%20target%3D%22_blank%22%3E%40mathetes%3C%2FA%3EThank%20you%20for%20replying.%20Much%20appreciated.%20I've%20attached%20an%20example%20of%20what%20I'm%20trying%20to%20get%20at.%20Hope%20it%20makes%20sense.%20I'm%20amazed%20at%20what%20Excel%20can%20do%20but%20not%20sure%20if%20what%20I'm%20hoping%20to%20do%20is%20beyond%20it%20(I%20doubt%20it!)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1445573%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20-%20returning%20multiple%20text%20strings%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1445573%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F675276%22%20target%3D%22_blank%22%3E%40hynguyen%3C%2FA%3EThank%20you%20for%20taking%20the%20time%20to%20build%20this%20example.%20It%20looks%20very%20complicated.%20I'll%20try%20to%20see%20if%20I%20can%20use%20it%20in%20the%20example%20I've%20just%20attached.%20Much%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1445583%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20-%20returning%20multiple%20text%20strings%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1445583%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F691078%22%20target%3D%22_blank%22%3E%40moncho47%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20variant%20if%20add%20list%20of%20possible%20variant%20in%20column%20O%2C%20and%20assuming%20your%20version%20of%20Excel%20supports%20TEXTJOIN%2C%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20291px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F197033iD4D8ECE3CB0C823F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Ein%20M2%20is%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DIF(%0A%20%20%20LEN(TEXTJOIN(%22%2C%20%22%2C1%2CIF(COUNTIF(B2%2C%22*%22%26amp%3B%24O%242%3A%24O%244%26amp%3B%22*%22)%2C%24O%242%3A%24O%244%2C%22%22)))%3D0%2C%0A%20%20%20%22apple%22%2C%0A%20%20%20TEXTJOIN(%22%2C%20%22%2C1%2CIF(COUNTIF(B2%2C%22*%22%26amp%3B%24O%242%3A%24O%244%26amp%3B%22*%22)%2C%24O%242%3A%24O%244%2C%22%22))%0A)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eand%20drag%20it%20down.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1445606%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20-%20returning%20multiple%20text%20strings%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1445606%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F691078%22%20target%3D%22_blank%22%3E%40moncho47%3C%2FA%3EI%20tried%20to%20show%20the%20thought%20process%20in%20producing%20the%20desired%20output%20in%20separate%20columns%20so%20that%20you%20can%20understand%20the%20ultimate%20formula.%20You%20only%20have%20to%20copy%20the%20formula%20in%20column%20H%20(as%20below)%20to%20where%20you%20want%20to%20display%20your%20result%20and%20change%20%24D%241%20to%20%22apple%22%2C%20%24E%241%20to%20%22orange%22%2C%20%24F%241%20to%20%22pear%22%20if%20you%20prefer%20hardcoding%20them.%20Note%20that%20the%20cells%20containing%20your%20text%20is%20assumed%20to%20be%20in%20column%20A%2C%20otherwise%20change%20its%20reference%20in%20the%20formula%20as%20well.%20I%20think%20this%20formula%20is%20not%20at%20all%20complicated%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3E%3DTEXTJOIN(%22%2F%22%2CTRUE%2CIF(ISNUMBER(SEARCH(%24D%241%2CA2))%2C%24D%241%2C%22%22)%2CIF(ISNUMBER(SEARCH(%24E%241%2CA2))%2C%24E%241%2C%22%22)%2CIF(ISNUMBER(SEARCH(%24F%241%2CA2))%2C%24F%241%2C%22%22))%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1446939%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20formula%20-%20returning%20multiple%20text%20strings%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1446939%22%20slang%3D%22en-US%22%3EThank%20you%20hynguyen.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi, Newbie here. Is have a cell that could contain apples and/or oranges and/or pears. I'm able to use an IF formula to extract either apples or oranges or pears but get a false value when the cell contains 'apples and oranges'. Is there a way to extract such a combination out of a cell?

7 Replies
Highlighted

@moncho47 

 

Could you post a representative spreadsheet that illustrates what you're describing. One that works on the one hand, but not on the other. It's hard to diagnose without actually seeing and experiencing the reality, no matter how clear your description is (and it's pretty good)...

 

I do realize that your apples and oranges is meant as an example, but I'm having a hard time visualizing why you can make the one condition work, but not the other.

Highlighted

@moncho47 If you do not care for the exact order of occurrence of the found texts in the cell, the attached workbook may return the results you want (use the formula in the last column, assuming that you have a list of your search texts in cell D1, E1, F1). It is always better to have the search texts listed and use reference in the formula to those cells rather than hardcoded. You can always expand the list of your search texts and simply add more components to the formula.

Highlighted

@mathetesThank you for replying. Much appreciated. I've attached an example of what I'm trying to get at. Hope it makes sense. I'm amazed at what Excel can do but not sure if what I'm hoping to do is beyond it (I doubt it!)

Highlighted

@hynguyenThank you for taking the time to build this example. It looks very complicated. I'll try to see if I can use it in the example I've just attached. Much appreciated.

Highlighted
Best Response confirmed by moncho47 (New Contributor)
Solution

@moncho47 

As variant if add list of possible variant in column O, and assuming your version of Excel supports TEXTJOIN,

image.png

in M2 is

=IF(
   LEN(TEXTJOIN(", ",1,IF(COUNTIF(B2,"*"&$O$2:$O$4&"*"),$O$2:$O$4,"")))=0,
   "apple",
   TEXTJOIN(", ",1,IF(COUNTIF(B2,"*"&$O$2:$O$4&"*"),$O$2:$O$4,""))
)

and drag it down.

Highlighted

@moncho47I tried to show the thought process in producing the desired output in separate columns so that you can understand the ultimate formula. You only have to copy the formula in column H (as below) to where you want to display your result and change $D$1 to "apple", $E$1 to "orange", $F$1 to "pear" if you prefer hardcoding them. Note that the cells containing your text is assumed to be in column A, otherwise change its reference in the formula as well. I think this formula is not at all complicated

=TEXTJOIN("/",TRUE,IF(ISNUMBER(SEARCH($D$1,A2)),$D$1,""),IF(ISNUMBER(SEARCH($E$1,A2)),$E$1,""),IF(ISNUMBER(SEARCH($F$1,A2)),$F$1,""))

Highlighted
Thank you hynguyen.