Return values from string that match defined range within a single cell

RaydenUK

Board Regular
Joined
Mar 25, 2014
Messages
74
How can I search through a string and return only the values that are in a defined named range within a singe cell? Ex: assume cell A1 contains the string "blue_yellow_red_orange". However, I want cell B2 to return only those substrings that are present in my named range "Colors", which contains yellow, orange, and purple. Therefore, the output for B2 should be "yellow, orange".
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
In B1 control+shift+enter, not just enter:
Rich (BB code):
=TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH("_"&Colors&"_","_"&A1&"_")),Colors,""))
 
Upvote 0
Thank you for the reply but I am using excel 2010 and there is no TEXTJOIN function. Is there an alternative to this?
 
Upvote 0
Thank you for the reply but I am using excel 2010 and there is no TEXTJOIN function. Is there an alternative to this?

Control+shift+enter, not just enter:
Rich (BB code):
=REPLACE(aconcat(IF(ISNUMBER(SEARCH("_"&Colors&"_","_"&A1&"_")),","&Colors,"")),1,1,"")
For this formula to work, add the following code for ACONCAT as a Module to your workbook using Alt+F11...

Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function
 
Upvote 0

Forum statistics

Threads
1,216,747
Messages
6,132,490
Members
449,730
Latest member
SeanHT

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