0
votes

In excel I have two sheets. In Sheet1 Column A, I have strings. In Sheet2 I have two columns, Column A contains one word that should potentially be somewhere in a string from Sheet1, and Column B has a return value that I would want if Sheet2!A:A was found anywhere in the strings in Sheet1!A:A. For Example:

Sheet 1:

Col. A                             **Col. B (These are the results I WANT from Sheet2)**
stackoverflow excel blue pony        Group2
grapes monkey help me                Group1
random words not very creative       Group3

And in Sheet 2, you have

 Col. A     Col. B
 monkey     Group1
 excel      Group2
 creative   Group3

I have been messing around with what basically comes down to a bunch of different iterations of a vlookup for Sheet1!B:B, but I can never get it to work right. The reason I have been focusing on vlookups is because of the need to return the value in Sheet2!B:B if Sheet2!A:A if found anywhere in Sheet1!A:A. I'm sure there is probably something much better out there for this solution than that, I am just stuck on this. Any help would be greatly appreciated.

2
I am so sorry everyone. It wasn't until I started reading your answers and reread my question again that I realized that I worded my question wrong. I cannot apologize enough, please accept my excuse that this issue has driven me crazy today and as a result, I have obviously lost my mind. I have rephrased my question, I want to return the value in sheet2 column B to sheet1 column B. If I could actually get a vlookup to work, it would go in Sheet1, column B.jenhil34

2 Answers

1
votes

Revised formula due to revised question

Try this formula in Sheet1 B2 copied down

=LOOKUP(2^15,SEARCH(Sheet2!A$1:A$4,A2),Sheet2!B$1:B$4)

That should work for your example but in a real situation you might get false matches because a search value of "key", for example, will match with "monkey". To prevent that you can use this version which only matches with whole words:

=LOOKUP(2^15,SEARCH(" "&Sheet2!A$1:A$4&" "," "&A2&" "),Sheet2!B$1:B$4)

0
votes

A little VBA might be your best bet here...

Sub finder()

Dim ws1, ws2 As Worksheet
Set ws1 = ThisWorkbook.Sheets("Sheet1")
Set ws2 = ThisWorkbook.Sheets("Sheet2")

Dim i As Integer

i = 1

Do Until ws2.Cells(i, 1).Value = ""
'The next line takes the value from sheet2, looks for it in sheet1 then puts 
'the value of the cell directly adjacent back into sheet2. This may fail if a 
'value is not found.

ws2.Cells(i, 2).Value = ws1.Range("A:A").Find(ws2.Cells(i, 1).Value).Offset(0, 1).Value
    i = i + 1
Loop

End Sub