search cell from list of possibilities

elmetal

New Member
Joined
Apr 17, 2013
Messages
16
Hello,

I have a list (let's say B2:B10) of things.
LISTOFSTUFFSTUFF
This is a dogHorse
This is cat's houseDog
Horses love this placeCat
Chicken

<tbody>
</tbody>

Now, what I want is a 3rd column that will look in column A and output which item in column B is present in that row. for example


LISTOFSTUFFSTUFFWhich
This is a dogHorsedog
This is cat's houseDogcat
Horses love this placeCathorse
Chicken

<tbody>
</tbody>


that make sense? basically I need it to search the A column for the presence of each item in column B and output which is present.

To keep things simple, let's say only 1 of each item in column b can be present in any value of column A
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Welcome to the board.

Try
=LOOKUP(2^15,SEARCH($B$2:$B$10,A2),$B$2:$B$10)

There cannot be any blanks in B2:B10.
If you really only have 4 items in STUFF, then change it to B2:B5
 
Upvote 0
will column A always be a short sentence
do you wish to search column B to match the animal in the sentence in say cell A1
 
Upvote 0
exactly. I used animals as an example. What I need is to search column A for any of column B contents, and if present, output which is present (let's assume only 1 can be present per cell, or none)

what I actually have is a spreadsheet of over 35000 rows all of which may or may not have a word in the list I have made up
 
Upvote 0
Here's a UDF solution:
Excel Workbook
ABC
1LISTOFSTUFFSTUFFWhich
2This is a dogHorseDog
3This is cat's houseDogCat
4Horses love this placeCatHorse
5Chicken#N/A
Sheet10


The UDF is:
Code:
Function Which(rCell As Range, rStuff As Range)
Dim vA As Variant
vA = Split(rCell, " ")
For i = LBound(vA) To UBound(vA)
    For j = 1 To rStuff.Rows.Count
        If InStr(LCase(vA(i)), LCase(rStuff.Cells(j, 1))) Then
            Which = rStuff.Cells(j, 1).Value
            Exit Function
        End If
    Next j
Next i
Which = CVErr(xlErrNA)
End Function
 
Upvote 0
Hey,

You dont need vba for that.

Code
=IF(COUNT(SEARCH("*cat*",C1,1)),"cat",IF(COUNT(SEARCH("*Dog*",C1)),"dog",IF(COUNT(SEARCH("*horse*",C1)),"horse",IF(COUNT(SEARCH("*chicken*",C1)),"chicken",""))))

Replace the animals in the formula of whatever you search and also C1 with the cell respective you want to search from.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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