Return cell content if a cell contains part of of text from another cell

andranos

New Member
Joined
May 28, 2014
Messages
9
Hello everyone, I'm currently looking a way to find a cell value if a cell contains part of of text from another cell
Might be easier for me to explain with image below so here we go

ABCD
Chicken, Beef, LambMeatBoiled EelFish
Orange, Apple, BananaFruitFried ChickenMeat
Trout, EelFishStir fry BroccoliVeggie
Cabbage, Carrot, BroccoliVeggieBanana SplitFruit

So basically the value from column D will be based on column C. If Column C contains word from Column A for example Boiled Eel contains Eel which is next to Fish from Column B, value for Column D would be Fish and so on

Thank you very much in advance guys!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
There may be a formula that can do this, but it escapes me. I was able, however, to create a user defined function to do what you want. See below.

Book7
ABCD
1
2Chicken, Beef, LambMeatBoiled EelFish
3Orange, Apple, BananaFruitFried ChickenMeat
4Trout, EelFishStir fry BroccoliVeggie
5Cabbage, Carrot, BroccoliVeggieBanana SplitFruit
6Another OneSomethingTwoNot Found
Sheet1
Cell Formulas
RangeFormula
D2:D6D2=SplitLookup($A$2:$B$6,C2)


VBA Code:
Public Function SplitLookup(LkupRange As Range, LkupValue As Range) As String
    Dim c As Range
    Dim NumWords As Long
    Dim v As String
    Dim i As Long, j As Long, t As Long
    
    If LkupRange.Columns.Count <> 2 Then
        SplitLookup = "#ERROR! Lookup Range must contain ONLY two columns"
        Exit Function
    End If
    
    If LkupValue.Columns.Count <> 1 Or LkupValue.Rows.Count <> 1 Then
        SplitLookup = "#ERROR! Lookup Value must contain ONLY one cell."
        Exit Function
    End If
    
    If LkupValue = "" Then
        SplitLookup = "#ERROR! Lookup Value cannot be blank."
        Exit Function
    End If
    
    NumWords = Len(LkupValue) - Len(Replace(LkupValue, " ", "")) + 1
    
    j = 1
    
    For i = 1 To NumWords
        t = InStr(j + 1, LkupValue, " ") - 1
        If t = -1 Then t = Len(LkupValue)
        v = Trim(Mid(LkupValue, i + j - 1, t))
        For Each c In LkupRange
            If InStr(1, c, v) > 0 Then
                SplitLookup = c.Offset(0, 1)
                Exit Function
            End If
        Next c
        j = InStr(j + 1, LkupValue, " ")
    Next i
    
    If SplitLookup = "" Then SplitLookup = "Not Found"
    
End Function
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
If your lists are not too long and IF you have the TEXTJOIN function (hence my previous post) you could try this formula approach.

andranos.xlsm
ABCD
1
2Chicken, Beef, LambMeatBoiled EelFish
3Orange, Apple, BananaFruitFried ChickenMeat
4Trout, EelFishStir fry BroccoliVeggie
5Cabbage, Carrot, BroccoliVeggieBanana SplitFruit
6Boiled Eel and TroutFish
7Baked Potato 
8Poached Chicken with Orange SauceMeat, Fruit
Sheet2
Cell Formulas
RangeFormula
D2:D8D2=TEXTJOIN(", ",1,UNIQUE(IFNA(INDEX(B$2:B$5,MATCH("*, "&FILTERXML("<p><c>"&SUBSTITUTE(C2," ","</c><c>")&"</c></p>","//c")&",*",", "&A$2:A$5&",",0)),"")))
 
Upvote 0

Forum statistics

Threads
1,215,016
Messages
6,122,700
Members
449,092
Latest member
snoom82

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