Match words from array into a string - excel

I have a cell which contains a description like the one below
"customer enjoys playing cricket and football."
Then on another worksheet I have a list of sports
Cell / Sport
A1: Tennis
A2: Football
A3: Golf
A4: Boxing
A5: Hockey
A6: Cricket
I need iterate through the list of sports and match the first sport in the list and then print it. Here are some examples of what I'd like to return.
Description / Sport (These are defined under 'Name Manager' as 'SPORT_NAMES')
"customer enjoys playing cricket and football." / Football (Because Football is in A1 and cricket is only in A6)
"customer is playing golf today." / Golf
"shall we play tennis or golf today" / Tennis
I am able to do it for each cell using the following formula
=IF(ISNUMBER(SEARCH(Sports!A1,Data!A2)), "Tennis", "")
Thanks,
Kieran

=INDEX($A$1:$A$6,MATCH(1,--ISNUMBER(SEARCH($A$1:$A$6,E1)),0)) - This is an array formula (enter the formula by using Ctrl+Shift+Enter while still in the formula bar)
By using a double unary operator you convert the TRUE / FALSE result of ISNUMBER(SEARCH($A$1:$A$6,E1)) to 0 or 1 respectively.
I then use MATCH() as the return value for INDEX() to get the appropriate result (which will always be the first occurrance)

I'm pretty sure there is a clean and nice way of doing this, but at least, this answer will work.
First of all. I strongly encourage you to list the sports as in my screenshot, with an auxiliary column that shows the importante of each sport. Thay way you can reorder as you want or change positions and remember priority:
Then, I used this dirty formula to get the results:
=IFERROR(IFERROR(IFERROR(IFERROR(IFERROR(IFERROR(IF(SEARCH('LIST OF SPORTS'!$B$2;Hoja1!A1)>0;'LIST OF SPORTS'!$B$2);IF(SEARCH('LIST OF SPORTS'!$B$3;Hoja1!A1)>0;'LIST OF SPORTS'!$B$3));IF(SEARCH('LIST OF SPORTS'!$B$4;Hoja1!A1)>0;'LIST OF SPORTS'!$B$4));IF(SEARCH('LIST OF SPORTS'!$B$5;Hoja1!A1)>0;'LIST OF SPORTS'!$B$5));IF(SEARCH('LIST OF SPORTS'!$B$6;Hoja1!A1)>0;'LIST OF SPORTS'!$B$6));IF(SEARCH('LIST OF SPORTS'!$B$7;Hoja1!A1)>0;'LIST OF SPORTS'!$B$7));"No sports found")
And in Sheet1 I get this:
Hope this can help you out.

Related

How to find from which cell text is contained in given cell

So I have a formula that shows if a cell contains text from a list:
=SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1)))>0
It works correct, but I need to further expand this formula.
I have a two data worksheet:
W1 is a list of companies and that show preferred companies for given product in given country,
W2 is a list of documents that show which company has been use in which country for which product.
I need formula that shows if for given document the company is preferred for given country and product.
Above formula solved the issue of company as it checks if company mentioned in W2 appears in W1, now I would need to add two more conditions, to check the country and product.
Current formula is this:
=IF(AND(SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1)))>0,"Preferred", "Non Preferred")
How do I reverse the formula so it will show me in WHICH cell the found value in W1 is so I can use simple VLOOKUP and = formula and and the conditions, like:
=IF(AND(SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1)))>0,B1=Vlookup(SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1))>0,Table in W1,1,"Preferred", "Non Preferred")
I am really stuck, please help.
An example of worksheet A
Company Name
Company Code
Country
abd
12355
Germany
aaa
23322
Austria
asc
432
France
asc
123
USA
asce
1234
Poland
An Example of worksheet B
Company Name
Country
abd - 111
Germany
aaa - 234
Austria
asc - 432
France
asc - 123
UK
asce - 1234
Romania
If I use:
=SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1)))>0
It will highlight 3 bottom rows, however I need to apply second condition so it will highlight ONLY 3rd row, the one with France.
Highlighting is pretty hard because CF rules don't allow to use references to other worksheets besides current one neither array formulas. But you may use a helper column to get the output you need and then hightlight based on that output:
Worksheet A
Worksheet B
Notice France is the only highlighted value because is the only country that fits pattern Company Name - Company&CodeCountry
Formula in column C (array formula, so you must introduce it pressing CTRL+ENTER+SHIFT:
={ISNUMBER(MATCH(A2&B2;'Worksheet A'!$A$2:$A$6&" - "&'Worksheet A'!$B$2:$B$6&'Worksheet A'!$C$2:$C$6;0))}
CR rule to highlight applied to column B is based on this formula:
=C2=TRUE()
UPDATE: If you really really need to skip the helper column, you may benefit from function INDIRECT:
INDIRECT
function
But if your dataset is big, I don't recommend this solution because it may really overcharge your file because INDIRECT is a volatile function:
INDIRECT – Excel’s Most Evil
Function
Besides, if your dataset is fixed (I mean it goes always in the same Address like A2:C6 or A2:A1000, whatever but always the same) you may use it, but it it changes all the time, it will slow down your file.
Anyways, you can make a CF rule based on this formula:
=ISNUMBER(MATCH(A2&B2;INDIRECT("'Worksheet A'!$A$2:$A$6")&" - "&INDIRECT("'Worksheet A'!$B$2:$B$6")&INDIRECT("'Worksheet A'!$C$2:$C$6");0))

VLOOKUP Excel: comparing columns

I am trying to do a very simple task that does not give me the expected results:
I got the following excel table with columns A and B:
Column A
Mr. John Doh
Mario Bros
Dr. Frankenstein
Mickey Mouse
Donald Duck
Column B
Jenny Dart
john doh
Roger Rabbit
Frankenstein
I am extracting values with VLOOKUP comparing B to A
=VLOOKUP("*"&B1&"*";$A$1:$A$5;1;FALSE)
however the result is the following:
Mr. John Doh
#N/A
#N/A
#N/A
If I do the contrary so comparing A to B:
=VLOOKUP("*"&A1&"*";$B$1:$B$5;1;FALSE)
I get the following result:
#N/A
#N/A
#N/A
Dr. Frankenstein
In both cases I would expect to see "Dr.Frankenstein" and "Mr.John Doh" appearing in both results
however, it seems not the case.
Any idea why?
There are no extra spaces in the cells
There are no Typos in the cells.
I tested the index 1 and the index 2 with no luck.
TRUE cannot be used as I am having "*"
The ultimate goal is to have a long list of users and pulling out data comparing the columns considering that some cells contain title+name like: "Mr." or "Dr."
In the A column you have "Mr. John Doh" and in B "john doh" so when using Vlookup to search john doh in A, it finds it. But in case you are searching "Mr. John Doh" it can't be successful because of the "Mr. " part of the string.
The same case with Frankenstein and Dr. Frankenstein in the other example. Strip the titles ("Dr", Mr. etc) and it will work.

Partial match when using vlookup formula

I'm trying to fill an empty column of a sheet with data from another sheet. For this I'm depending on VLOOKUP
Here is my formula
=VLOOKUP(RC[-6],Sheet2!C[-3]:C[-2],2,FALSE)
I'm looking for a name in a sheet and takes value from that row. But the issue I'm facing is sometime the value in sheet2 (Where I have to do vlookup) which is actually a person's name doesnt have middle name. It only have first and last name. Since the lookup value as middle name, in that situation the lookup doesn't yields any result. So the plan is to do lookup with the first and lastname only even there is middle name in the lookup value. How can we accomplish that
For example our lookup value (RC[-6]) could be Donald John Trump. But in search sheet (Sheet2) the name could be only Donald Trump. So in result I need Donald Trump row, but it's not since we have Donald John Trump as lookup value.
You can use wildcards in VLOOKUP like the asterisk * for any amount of characters or the ? for one character.
So if your search term is Donald Trump but you want to find also Donald John Trump then you need to add an asterisk Donald *Trump:
=IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=1,LEFT(A1,FIND(" ",A1)-1) & " *" & RIGHT(A1,LEN(A1)-FIND(" ",A1)),A1)
Or if your search term is Donald John Trump but you want to find also Donald Trump then you need to substitute the middle name with an asterisk Donald *Trump:
=IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=2,LEFT(A1,FIND(" ",A1)-1) & " *" & RIGHT(A1,LEN(A1)-FIND(" ",A1,FIND(" ",A1)+1)),A1)
You can then use the above formula as first argument in your VLOOKUP, or use a helper column so you can see what the actual search term is.

Excel formula to find ColumnA value in CoulmnB that has sentence

I am looking for a way to find the match in Column A to B and highlight. I tried many excel formulas in the forum but unlucky in getting it work.
For eg..
**ColumnA**
John23
Peter
Nick5
Kevin4
T12345
ColumnB
John23 is outside the yard
Kevin4 is the famous guy
ABC is with Nick5
Who is the person at the door. is it Peter?
R345 Qrtfjd T12345
Kevin is not the match
Only Kevin4 is the match
John is not the match
=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($A$1:INDEX(A:A,MATCH("zzz",A:A)))/(ISNUMBER(SEARCH($A$1:INDEX(A:A,MATCH("zzz",A:A)),B1))),1)),"")

Excel function: If cell is equal to another cell in range, return three other items

I am working on an excel document for meal-planning. I am trying to create a function that will allow me to search to see if the meal is in a column, and if the meal is in the column, then return the ingredients.
The first sheet looks something like this:
Breakfast Lunch Dinner
Monday Cereal PB&J
Tuesday Pizza
Wednesday Coffee
Thursday PB&J
Friday
In the second sheet, I have the recipes written like this:
PB&J Peanut Butter Jelly Bread
Pizza Cheese Sauce Pie Crust
I want to search the first sheet for all instances of a recipe, lets say PB&J. And If PB&J shows up, I want it to return Peanut Butter, Jelly, and Bread (my shopping list).
I am not sure how to write a function that may return more than one item, however. Any help would be greatly appreciated!
Let's say your sheets are set up like this:
Sheet1:
So your days of the week and food options are at the top.
Sheet2, your ingredients lists, is like this:
Back on Sheet1, let's use A7 as the food you want to look up. In B7, you can use a simple VLOOKUP():
=VLOOKUP($A7,Sheet2!$A$1:$K$3,COLUMN(),FALSE)
and drag right a bunch of columns. To hide the 0 returns, just wrap the formula in an IF statement:
=IF(VLOOKUP($A7,Sheet2!$A$1:$K$3,COLUMN(),FALSE)=0,"",VLOOKUP($A7,Sheet2!$A$1:$K$3,COLUMN(),FALSE))
Here is what you can do. Lets say the sheet with ingredients is named 'Ingredients'. You can first check in a 'Exists' column as to whether the particular instance of recipe exists in the range. Then, if it exists another column can show the ingredients as a comma separated list.
Formulas:
Recipe exists : `=COUNTIF($B$2:$D$6,"*"&F2&"*")>0`
Get Ingredients : `IF(G2,TEXTJOIN(", ",TRUE,Ingredients!B1:Ingredients!D1))`
Col F contains the recipe names,
Col G indicates whether the recipes exists in the range.

Resources