Return Array Value If That Value Exists Within A Text String

a_faulding

New Member
Joined
Jul 14, 2020
Messages
8
Office Version
  1. 365
Hello,

I am building a spreadsheet and want to check whether a value in an array exists within a text string. If the value within the array does exist within the text string, I would like to return the array value.

For example:

StringDesired ResultArray Column 1
Tasty ApplesAppleApple
Pomegranate-Banana
Orange PeelOrangePear
123PearPearOrange
Pineapple-Grape

If possible, I would also like to be able to do this with a multi-column array, e.g:

StringDesired ResultArray Column 1Array Column 2Array Column 3
Tasty ApplesAppleBananaOrangeGrape
Pomegranate-AppleMangoStrawberry
OrangeOrangeMangoGrapeMango
123PearPearGrapeStrawberryApple
Pineapple-StrawberryMangoPear

And finally...

Could I do this by referencing a named table instead of a selection, so if new values get added to the bottom of the table, the formula automatically references the full table?

Thanks!

Andrew
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hello I tried solving the first part of the question. I hope this helps.
Book1
ABCD
1StringDesiredArray Column 1
2Tasty ApplesAppleApple
3Pomegranate-Banana
4Orange PeelOrangePear
5123PearPearOrange
6Pineapple-Grape
Sheet1
Cell Formulas
RangeFormula
B2:B6B2=IFERROR(INDEX($D$2:$D$6,IF(SUMPRODUCT(--ISNUMBER(FIND($D$2:$D$6,A2)),MATCH(ROW(D2:D6),ROW(D2:D6)))>0,SUMPRODUCT(--ISNUMBER(FIND($D$2:$D$6,A2)),MATCH(ROW(D2:D6),ROW(D2:D6)))," ")),"-")
 
Upvote 0
Will it ever be possible that more than one array value might be found in the text? eg "I like Apple and Pear"

Assuming that the answer is "No" or "Yes but I just want any one of them returned", then see below.

I am also assuming that this is a case-sensitive search since you want to find "Apple" in "Apples" but you do not want to find "apple" in "Pineapple".

So for the first question

20 08 20.xlsm
ABCD
1StringDesiredArray Column 1
2Tasty ApplesAppleApple
3Pomegranate Banana
4Orange PeelOrangePear
5123PearPearOrange
6Pineapple Grape
7I like Apple and PearPear
Array Value
Cell Formulas
RangeFormula
B2:B7B2=IFERROR(LOOKUP(9.99E+307,FIND($D$2:$D$6,A2),$D$2:$D$6),"")


Could I do this by referencing a named table instead of a selection,
See if this would work for you.

Turn the columns of values into a formal Excel table (mine is called 'Table1') then try this

20 08 20.xlsm
ABCDEF
1StringDesiredFruit 1Fruit 2Fruit 3
2Tasty ApplesAppleBananaOrangeGrape
3Pomegranate AppleMangoStrawberry
4Orange PeelOrangeMangoGrapeMango
5123PearPearGrapeStrawberryApple
6Pineapple StrawberryMangoPear
7I like Apple nad PearApple
Array Value (3)
Cell Formulas
RangeFormula
B2:B7B2=TRIM(LEFT(SUBSTITUTE(TEXTJOIN(",",1,IF(ISNUMBER(FIND(Table1,A2)),Table1,"")),",",REPT(" ",50)),50))
 
Upvote 0
Thank you both for your responses.

Good spot regarding pineapple! I was too busy thinking about different fruits to realise it also contained "apple"!..

Peter - your last suggestion seems perfect. I actually did not want it to be case-sensitive, so I just swapped out FIND for SEARCH.

Cheers!

Andrew
 
Upvote 0
I actually did not want it to be case-sensitive, so I just swapped out FIND for SEARCH.
So you are happy to have Apple returned for Pineapple? (or Pear returned for Appearance?) :unsure:
 
Upvote 0
Hi Peter, in the context of the actual sheet, that will not be an issue but thanks for making me aware.

One thing I did just notice, is that I cannot use the returned values from your suggestion for a secondary lookup as there are loads of apparent spaces after the value - despite using the TRIM function.

Is there a solution for getting rid of these surplus spaces to return a clean string?
 
Upvote 0
One thing I did just notice, is that I cannot use the returned values from your suggestion for a secondary lookup as there are loads of apparent spaces after the value - despite using the TRIM function.
I don't have that - see below in column H that the right hand 3 letters of the result are exactly as they appear to be in column B. Must be something different about your data.

Can you post a small sample with XL2BB so that we can copy exactly what you have?

20 08 20.xlsm
ABCDEFGH
1StringDesiredFruit 1Fruit 2Fruit 3
2Tasty ApplesAppleBananaOrangeGrapeple
3Pomegranate AppleMangoStrawberry 
4Orange PeelOrangeMangoGrapeMangonge
5123PearPearGrapeStrawberryAppleear
6PineappleAppleStrawberryMangoPearple
7I like Apple nad PearAppleple
8AppearancePearear
Array Value (3)
Cell Formulas
RangeFormula
B2:B8B2=TRIM(LEFT(SUBSTITUTE(TEXTJOIN(",",1,IF(ISNUMBER(SEARCH(Table1,A2)),Table1,"")),",",REPT(" ",50)),50))
H2:H8H2=RIGHT(B2,3)
 
Upvote 0
Hmm strange. Afraid I can't install XL2BB (work computer) but I did manage to create a workaround after cleaning my data and creating a table called Fruit, with just one column:

{=IFERROR(INDEX(Fruit,MATCH(TRUE,ISNUMBER(SEARCH(Fruit,A2)),0)),"")}

Could this formula be modified to work with a table with multiple columns?

Thanks,

Andrew
 
Upvote 0
Afraid I can't install XL2BB
Could you upload a small sample file with dummy data to DropBox, Google Drive etc and provide a shared link here?
If so, can you also include whatever is required to demonstrate the "loads of apparent spaces" issue described in post #6?

Also, what about the answer to this question that I asked earlier?
Will it ever be possible that more than one array value might be found in the text? eg "I like Apple and Pear"
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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