Return first row number in range where string matches any part of cell contents - excel

Say I have three cells (one in each row):
A1
Apple Pear Lime Grape
Tom Bob Cliff Steve
Pi Rho Sigma Theta
There is a string of text in each single cell. Is there a formula I can write that will return the first row in which a given value appears?
For example, say I had cells like this:
Pear 1
Cliff 2
Steve 2
Pi 3
I would like to return the row where that value is a match for the original array of strings. I have experimented with SEARCH, FIND, and others, but these are good for comparing one row to another single row. I'm looking for something that will examine a whole array of rows and return the first reference row.

use MATCH with wildcards:
=MATCH("*"&C1&"*",A:A,0)

Related

Excel Formula to return all rows and columns corresponding to search string

I'm trying to lookup two sheets in Spreadsheet.
One has the search value and other has all the data corresponding to the search string.
I'm trying to find a formula that will search the value and return all the corresponding rows. Another thing is that it has to return the entire row and columns correspoing to that string and not only one.
I'm using this Vlookup formula as of now but any help will do:=
ArrayFormula(VLOOKUP(A1,Sheet2!A2:AE196,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24},FALSE))
A2:is the seach string, and used array to define the Columns to be returned.
But the formula returns only one row corresponding to the string and not all the rows.
Is there a formula that returns all rows and entire values in those rows correspoinding to the search string?
EX :Sheet1:search criteria
Search
Apple
Mango
melon
Ex:Sheet 2: Data
Name
Colour
no
Apple
red
5
Banana
yellow
3
Apple
red
25
Mango
yellow
1
Mango
yellow
10
Expected result for Apple(A1 in the formula) as search string:
Name
Colour
no
Apple
red
5
Apple
red
25
Actual result:
Name
Colour
no
Apple
red
5
You should use FILTER or QUERY
=FILTER(Sheet2!A2:AE196,Sheet2!A2:A196=A1)
=QUERY(Sheet2!A2:AE196,"select * where A='"&A1&"'",1)

Excel SumProduct with if Statement in a cell.

I have a basic problem in Excel. I have a row with names and one with numbers. I try to find what is the sum of these numbers for a special name.
ex.
A B
Apple 12
Apple 12
Kiwi 9
Apple 4
Banana 51
Kiwi 12
Banana 4
Kiwi
So far I just use a basic sumproduct which works well. Like
=Sumproduct((A1:A8=A1)*(B1:B8)
This formula gives me back my total number of Apples
(12+12+4).
The problem is, if a cell contain some formula, then I have #VALUE! result.
Let say the last cell called Kiwi contain a code like
=if(A64="", "", 12)
Then it makes Kiwi empty if A64 is empty. Great.
But sumproduct don't work anymore.
I can't sort the name... any ideas?
Thank you
You can simply use =SUMIF() formula to get sum of these numbers for a special name.
=SUMIF($A$1:$B$64,A1,$B$1:$B$64)
or
=SUMIF($A$1:$B$64,"kiwi",$B$1:$B$64)
You can change these ranges based on your list. (You can even define dynamic name in Name Manager and then you can use that Name as your range.)
It's not the fact that your cell is calculated (contains a formula), it's because the result of the formula is a text.
Maybe you could use à 0 instead of the 0-length text and apply conditional formatting to your cells (font colour white if 0 value)
=if(A64="", 0, 12)

How to Count the number of times a cell in one column matches a cell in another column?

I have two columns. Column A is a list of text values. Column B will be individual text values that may or may not match Column A. Across say 20 rows, I want to use something like COUNTIF at the bottom of Column B to count how many answers in Column B match the correct answer in Column A.
For example, if Column A reads:
1. Apple
2. Orange
3. Banana
4. Kumquat
5. Pineapple
Column B reads:
1. Apple
2. Guava
3. Pistachio
4. Kumquat
5. Pineapple
Essentially, rows 1, 4 & 5 all match, thus the sum at the bottom of column B would be 3.
Is there a way to do this with a formula?
You can use something like this:
{=SUM(IF(A1:A5=B1:B5,1,0))}
To use this formula, type in any cell "=SUM(IF(A1:A5=B1:B5;1;0))" and press CTRL+SHIFT+INTRO

Excel sort table value and return row names of the 5 largest rows

As stated in the title, the table has two columns, one for row names and the other is for values, I just want to return the row names and values of the 5 rows with the largest value accordingly back to another range of cells. (It will be better if I don't have to operate the table)
Thank you very much!
for example the table is like:
Johnny 1
Harry 2
Jessie 3
Luke 4
Mary 2
Lucy 1
Peter 5
Basically I would like the ouput to be
Peter 5
Luke 4
Jessie 3
Harry 2
Mary 2
The fifth biggest number you get like this
=LARGE($B$1:$B$10;5)
and then you will find the row number of this value with MATCH and use this in INDEX to get the text value
=INDEX($A$1:$A$10;MATCH(LARGE($B$1:$B$10;5);$B$1:$B$10))
Now this will not work, if you have values appearing twice. Then an additional column could help or some more complicated trick for the MATCH part, like
MATCH(LARGE(B1:B10-ROW(B1:B10)/1000;1);B1:B10-ROW(B1:B10)/1000;0)
And then you have to make an array function out of the formula but pressing CTRL+SHIFT+ENTER not only ENTER. Then {} will be added around the formula.

Return value of last match

I need a formula to return the value of Data for the last match of "Text". Row number is also acceptable. Macro is NOT acceptable. Name column is unsorted and cannot be sorted!
Only column "Name" is used as lookup value. I would rather use a/multiple helper column(s) instead of an array formula.
Row Name Data
1 Joe 10
2 Tom 20
3 Eva 30
4 Adam 40
5 Tom 21
LARGE only works with numbers, and VLOOKUP only returns the first match. LOOKUP only works sometimes, so its out too.
So if I wanted the last match for "Tom" then it should return "21".
Array formulas could be avoided with a helper column.
Suppose to have in F1 the name to match (i.e. Tom)
In the helper column row C2 enter
=IF(A2<>$F$1,0,row())
Then copy the formulas along your data.
Now the column C contains 0 for the unmatched names and the row number for the matched ones. Maxing the column yield the row of the solution.
Now the result is simple a matter of using the correct offset with the function offset:
=OFFSET(B1,max(C:C)-1,0)
PS: my copy of excel is in italian, so I can't test this english translaction of the formulas.
I think it's the easiest way to make it.
=LOOKUP("Tom";A2:B7)
Create a column with an array formula (enter it with Ctrl+Shift+Enter):
=VLOOKUP(MAX(IF($B$2:$B$6=B2, $A$2:A$6, 0)), $A$2:$C$6, 3, FALSE)
To make sure you did it right, click on the cell, and the formula should be shown encased in curly brackets ({}).
Note: This assumes that "Row" is in A1.
I have come up with a solution, but it requires that numbers in Data are concurrent, like so
Name Data
Joe 1
Tom 1
Eva 1
Adam 1
Tom 2
Tom 3
Eva 2
But thats okay, since that my data looks like that anyway. So if Name is used before then it must be the old highest +1 aka concurrent.
Name is A1 and Data is B1, and this formula goes into C2:
FLOOR(SQRT(2*SUMIF(A2:A7,A2,B2:B7)),1)

Resources