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

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)

Related

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

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)

Excel formula to check if items from a comma separated list in one cell exist in a comma separated list in another cell?

I have a spreadsheet where every row has two columns, each containing a comma separated list of words or phrases.
Column 1 | Column 2
---------------------------------------------------------
Orange, Pear, Sugar apple, Kiwi | Orange, Sugar apple
Banana, Watermelon, Pomegranate | Strawberry, Banana
I'm trying to create a formula that checks if the items listed in Column 2 are a subset of the items listed in Column 1 and outputs true or false.
In the above example the output should be true for Row 1 and false for Row 2.
The solutions I tried using the search and find functions only work if the items in Column 2 are listed in the same sequence, i.e. if Column 2 is a substring of Column 1.
Use this array formula:
=AND(ISNUMBER(SEARCH(", " & TRIM(MID(SUBSTITUTE(B1,",",REPT(" ",99)),(ROW($XFD$1:INDEX(XFD:XFD,LEN(B1)-LEN(SUBSTITUTE(B1,",",""))+1))-1)*99+1,99)) & ",",", "&A1&",")))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode

Excel: How to add a column from other sheet based on a key column?

I have 2 list. Both have a lot of column. I would like to insert a column from Sheet2 to Sheet1 based on a ceratin key column. Also sheet2 have much more rows than sheet1 so it ll be inserted only partly and still there ll be elements with no matches. For an example:
Sheet1:
Names ID Car Color
John 1 Audi Empty
Andy 4 Toyota Empty
Mike 3 BMW Empty
Tony 2 Suzuki Empty
Sheet2:
ID Cost Color
6 200 Blue
3 200 Red
4 300 Green
5 100 Red
1 50 Black
I would like to get the "color" from Sheet2 to Sheet1 by using the "ID". Using Excel 2010. I suspect I need INDEX+MATCH combination, but the examples I can find are not detailed and more simple so I coudn't figure out how to use them.
How about inserting this formula on Column D in the first row, then dropping the formula down:
=VLOOKUP(B1,Sheet2!$1:$1048576,3,FALSE)
Or to find the column that contains "Color", use Index Match Match, as follows:
=INDEX(Sheet2!$1:$1048576,MATCH(Sheet1!B2,Sheet2!A:A,0),MATCH("Color",Sheet2!$1:$1,0))
This will find the value in Column B in Sheet2 and give you the row number, then it will find the Column that contains "Color" and return the Column number, with those two numbers Index will return your color.

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)

Count how many distinct values (or get list of distinct values) in a filtered column

Is there a way to count the number of distinct values in a filtered column in Excel?
Using the formula at https://exceljet.net/formula/count-unique-values-in-a-range-with-countif I can count the number of distinct values in a range, but when that range has been filtered with an auto-filter I still get the unfiltered count.
For example:
A B
1 Scarf Blue
2 Hat Red
3 Gloves Green
4 Coat Blue
5 Balloon Red
6 Shoes Blue
Counting unique values in B with =SUMPRODUCT((B1:B6<>"") / COUNTIF(B1:B6,B1:B6 & "")) should return 3 as the distinct values are Red, Green and Blue.
If I auto filter Column B to just select Red items, the resulting table will look like:
A B
2 Hat Red
5 Balloon Red
In this case the number of distinct values retuned should be 1. But the formula above still returns 3.
The formula should also cope with multiple selections in the auto-filter, so for example filtering for Blue and Green should result in the following table:
A B
1 Scarf Blue
3 Gloves Green
4 Coat Blue
6 Shoes Blue
From which the formula should return 2 (Blue, Green).
Finally, if I am filtering on column A rather than B, the formula should still work. So If I am only interested in Hat, Scarf and Coat, filtering column A for these values would result in:
A B
1 Scarf Blue
2 Hat Red
4 Coat Blue
From which the formula should return 2.
(I'm using Excel 2013 and need to do this in a formula rather than using VBA etc)
I also found this page on office.com which I thought might help, but alas I can't get it to work for me.
This reference shows how you can exclude hidden rows using AGGREGATE
Excluding hidden rows with AGGREGATE
You can then use a standard way of counting unique values like this
Counting unique values with FREQUENCY
So if you were counting values in column B, you would need a helper column (say C) containing
=IF(AGGREGATE(3,5,B2),B2,"")
Then plug in the form of count unique that ignores empty cells
=SUM(IF(FREQUENCY(IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""), IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""))>0,1))
Or your formula if you prefer
=SUMPRODUCT((C2:C10<>"") / COUNTIF(C2:C10,C2:C10 & ""))

Resources