Vlookup all the values matching the search term instead of just one. - excel

So the following formula returns only the first value from the range. I kinda need all the matching search results indexed instead of just 1.
=Vlookup("*" & B3 & "*",A:A,1,0)
SPREADSHEET LINK

With Google Sheets use Query:
=QUERY(A:A,"select A where A contains """ & B3 &"""")
Since you have the Excel tag use this formula for excel:
=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($A$2:INDEX(A:A,MATCH("ZZZ",A:A)))/(ISNUMBER(SEARCH($B$3,$A$2:INDEX(A:A,MATCH("ZZZ",A:A))))),ROW(1:1))),"")
Copy/drag it down sufficient for your needs.

Another option is
=FILTER(A2:A, SEARCH(B3, A2:A))
Filters out those values where the string can be found and also supports wildcards within the string or could be extended to match a regular expression instead.

vlookup is designed to always give you one result. Either your query matches then it will return the value, else it will return an error. As you want all the values I would recommend a different approach.
Create a column next to your column (in your case A:A) and fill it with your condition =IF($A1 = ("*" & B3 & "*", 1, 0). This column should be filled with 0 and 1 depending on the content of your column B.
Do whatever you want with the values in column A, and take your newly created column as condition. For example to sum all values in column A that match your condition: =SUMIFS(A:A, B:B, "=1")
I hope this helps to streamline your Excel. If you need further help maybe elaborate on the content of your columns A and B and what you want to achieve with your =vlookup().

Related

Use VLOOKUP with split ranges

I'm making a formula that looks up a value and returns a value, fairly simple procedure as I can use VLOOKUP or INDEX-MATCH. However, I cannot seem to create or find a way to make it work when the ranges are located side by side. (Will provide example)
I know I could move all the data into two columns, but that would make it Very long and the table is often looked at for reference. I would like to keep the table the way it is.
What I am looking for is that I can type the tank level(inches) into a cell and next to it it will return the tank level(gallons).
My current formula is
=INDEX('Calib. A & B'!$B$3:$B$47,MATCH(TANKS!$E$2,'Calib. A & B'!$A$3:$A$47,1))
Currently it compares cell E2 with A3:A47 and returns the corresponding value in B3:B47. It needs to search columns C, E, G, I, etc. Any ideas other than rearranging the spreadsheet?
There are different ways of obtaining the relevant rows/columns for the lookup:
=INDEX('Calib. A & B'!$A$3:$U$47,AGGREGATE(15,6,1/((TANKS!$E$2='Calib. A & B'!$A$3:$U$47))*ROW('Calib. A & B'!$A$3:$U$47)-2,1),AGGREGATE(15,6,1/(TANKS!$E$2='Calib. A & B'!$A$3:$U$47)*COLUMN('Calib. A & B'!$A$3:$U$47)+1,1))
The -2 for the rows argument of the index function is to adjust for the header position.
The +1 for the columns argument is to return the value one column to the right of the cell that matched.
This assumes, of course, that the values matching the lookup_value in E2 are only found in the "odd" columns of the data range.
As suggested by #TerryW, if your measure in E2 is not an exact match to the value in the data table (and the data table measurements are exact to the 1/8), you can roundup E2 to the next 1/8th.
Replace TANKS!$E$2 with ROUNDUP(TANKS!$E$2*8,0)/8
One way is with a long formula basically doing a union of results of the match on each column but having result as empty string when do not match it.
So we do a match against column A, if it doesn't find it it returns a blank string, if it finds it returns the number , then does the same for column C and concatenates the results and uses this on the index.
BUT this will only work if you search for an exact match.
For example:
=INDEX('Calib. A & B'!$B$3:$B$47,IF(ISNA(MATCH(TANKS!$E$2,'Calib. A & B'!$A$3:$A$47,0)),"",MATCH(TANKS!$E$2,'Calib. A & B'!$A$3:$A$47))&IF(ISNA(MATCH(MATCH(TANKS!$E$2,'Calib. A & B'!$C$3:$C$47,0)),"",MATCH(MATCH(TANKS!$E$2,'Calib. A & B'!$C$3:$C$47)))
You would need to add one more section for each column.

Formula to find part of a cell's value as exact match to a value from other cells

On tab 1, I have data down column B that contains string values like this:
\\ABC\VOL1\DATA\Dan\Personal Folders
\\ABC\VOL1\DATA\Mike\My Stuff\Docs\Support
\\ABC\VOL1\DATA\Mike\My Stuff\Photos
\\ABC\VOL1\DATA\Bob\Plans
On tab 2, I have data down column C that I want to use as a lookup table like this:
\\ABC\VOL1\DATA\Adam
\\ABC\VOL1\DATA\Steve
\\ABC\VOL1\DATA\Mike
\\ABC\VOL1\DATA\Ronnie
I need a formula I can put on tab 1 down column C to see if any part of each text string from tab 1, column B matches any complete text string from tab 2, column C. So for example, I would place this formula to show Yes or No like this:
Column B......................................................................Column C
\\ABC\VOL1\DATA\Dan\Personal Folders....................No
\\ABC\VOL1\DATA\Mike\My Stuff\Docs\Support..........Yes
\\ABC\VOL1\DATA\Mike\My Stuff\Photos.....................Yes
\\ABC\VOL1\DATA\Bob\Plans.......................................No
I have tried VLOOKUP, INDEX/MATCH, ISNUMBER/SEARCH, and COUNTIF as an array with wildcards, but I just cannot seem to figure it out. Currently, with COUNTIF as array, I have this:
=COUNTIF(B2,"*" & 'Tab 2'!$C$2:$C$1000 & "*")
This is the start to return the array results, but the results aren't as I would expect as I get "0" when I should get "1" for certain rows.
If anyone can help me out with a formula (not VBA) using any of the functions mentioned above or any others, I would greatly appreciate it. Thanks.
use this array formula:
=IF(COUNT(SEARCH('Tab 2'!$C$2:INDEX('Tab 2'!$C:$C,MATCH("zzz",'Tab 2'!$C:$C)),B2)),"Yes","No")
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
This will search the cell for any of your criteria and return the number of matches if there is a match (which unless you have duplicates in the criteria it will be a 1).
Enter as array.
{=COUNT(SEARCH($C$1:$C$4,B1))}

excel: if cell contains multiple criteria then return multiple criteria, nestled?

I have 4 criteria lists that look like this:
A B
Name Category
Name Category
Name Category
And a MasterList like this:
A B
stuffNAME Category
NAMEstuff Category
NAME Category
I would like to know if there is a formula that can search through each criteria list based on the MasterlistA column for "NAME" and return the appropriate "Category" in MasterlistB.
As an example:
I'm looking to return MasterlistB based on MasterlistA
Criteria List:
A B
NBC NBCU
Disney ABC
Masterlist:
A B
NYC NBC 20998 NBCU
NJ2987 NBC NBCU
Disney Florida99 ABC
I'm simplifying, but in reality the criteria lists all refer to different masterlist columns as well. Trying to get the matching/searching part down first.
Given a setup as shown in #ScottCraner 's answer:
In cell E1 and copied down:
=IFERROR(LOOKUP(1,1/COUNTIF(D1,"*"&$A$1:$A$2&"*"),$B$1:$B$2),"No Match")
This is a regular formula and does not require array entry.
You can do this using VLOOKUP, nested with the IFERROR statement.
I am assuming each table is starting on A1, in sheets called Sheet1, Sheet2, Sheet3, and Sheet4. You may need to adjust references to point to appropriate tables.
The basic formula to find the category which matches your name, is simply [assuming your search term is on a new sheet on A1, let's say Sheet5, with the rest of your final data table]:
=VLOOKUP(A1,'Sheet1'!A:B,2,0)
This simply takes the value in A1 [the search term], tries to find it in column A of sheet 1, and if it does find it, takes the first matching row, and returns the value on the 2nd column in [column B, with the category].
If that fails, you simply put that inside of IFERROR, which attempts to calculate something, and if it creates an error, returns something else, like so:
=IFERROR(VLOOKUP(A1,'Sheet1'!A:B,2,0),"NO MATCH FOUND")
Now to use the IFERRORS to first attempt to find a match on Sheet1, then Sheet2, etc., put the following:
=IFERROR(VLOOKUP(A1,'Sheet1'!A:B,2,0),IFERROR(VLOOKUP(A1,'Sheet2'!A:B,2,0),IFERROR(VLOOKUP(A1,'Sheet3'!A:B,2,0),VLOOKUP(A1,'Sheet4'!A:B,2,0))))
To search for only a partial match, you can use the following:
=VLOOKUP("*"&A1&"*",'Sheet1'!A:B,2,0)
The "*" act like wildcards, and if they are included in front of and behind your search term [in this case, A1], then anything that contains your search term, regardless of its position in a cell, will be considered a match. You can replace A1 in all of my above formulas with this revised wildcard match to check for partial matches in any of your sheets.
To search a list of items, which exactly match a part of your search term
You could probably do this with an array formula, but because you have multiple data tables, I think the easiest solution is to use a helper column next to each of those tables, to create a unique ID which actually matches to your Master List. ie:
On Sheet1 [and all other category sheets], insert a new column in between A & B; this column will trace back from column A, to match a Name from your Master List on Sheet5, like so [starting in B1 & copied down]:
=VLOOKUP("*"&A1&"*", 'Sheet5'!A:A, 1, 0)
Your revised formula in your master sheet would now look like this:
=IFERROR(VLOOKUP(A1,'Sheet1'!B:C,2,0),IFERROR(VLOOKUP(A1,'Sheet2'!B:C,2,0),IFERROR(VLOOKUP(A1,'Sheet3'!B:C,2,0),VLOOKUP(A1,'Sheet4'!B:C,2,0))))
Rather than placing the four lists side-by-side like:
Stack them on top of each other like:
The its as simple as:
=VLOOKUP("David",A1:B12,2)
So here is the basic formula to get what you want:
=INDEX($B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & $A$1:$A$2 & "*",D1))),1))
if you have 2010 or later. If you have 2007 and earlier than you will need to use the following array formula:
=INDEX($B$1:$B$2,SMALL(IF(ISNUMBER(SEARCH("*" & $A$1:$A$2 & "*",D1)),ROW($1:$2)),1))
It being an array formula it must be confirmed with Ctrl-Shift-Enter.
In the picture, the first formula is Column F, the second in Column E
You will need to add nested IFERROR() Functions for the various sheets.
=IFERROR(INDEX(Sheet1!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet1!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet2!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet2!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet3!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet3!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet4!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet4!$A$1:$A$2 & "*",A1))),1)),"NOT HERE"))))

Find partial match between two columns and return a third column

I'd like to create a formula that looks for a partial match in two columns in two different Worksheets, and if there is a partial match between the two columns, it returns the value of a different column in Worksheet 2.
Example:
Sheet 1 Column A:
Dev
Tim
Jon
Sheet 2 Column A:
Development
Timothy
Jonathan
If there is a partial match as there is in these fields, I want it to return the value from Sheet 2 Column B.
Currently I have the following formula:
=INDEX(ValueIWant,MATCH(A1,ColumntoPartialMatchAgainst,0))
However, this returns the "ValueIWant" field only when there is an exact match.
How can I modify this formula to work with even a partial match?
Please try:
=VLOOKUP(A1&"*",`Sheet 2`!A:B,2,0)
Note this deliberately only adds a wildcard (*) to the end of the Sheet 1 values to reduce the risk of a match with something like estimate.
To achieve the desired result you should concatenate wildcard(s) to the value to search. In your formula, instead of A1, please try:
A1 & "*" - if you want to match only the beginning of array values (like in your sample data)
"*" & A1 & "* - to match any part of array values

Looking up a value in a specified column

Something I've wanted to do quite a bit lately, and can't work out how to do, is MATCH in a column I pass as an argument. Essentially, I have a two dimensional array, and I want to be able to find the first occurrence of a given value in the nth column, for any given value of n, and return the row number it occurs at. Alternatively (and more-or-less equivalently), I want to be able to search in the column with a given column header. Is there any way to do this?
Effectively, I want to simulate the non-existent function =MATCH(lookup_value,lookup_array,lookup_column,[match_type])
I've kludged together a horrible bodge job using INDIRECT, which works, but offends me horribly.
=MATCH(lookup_value,INDIRECT("R"&<top of array>&"C"&<left of array>+<column reference>&":R"&<bottom of array>&"C"&<left of array>+<column reference>,FALSE),FALSE)
This formula should work for you and will avoid INDIRECT. Anytime you can avoid using Indirect, I recommend doing so.
=MATCH(lookup_value,INDEX(lookup_array,0,MATCH(lookup_header,array_headers,0)),0)
If you aren't looking up the column by column header and just have the column number, then it becomes easier:
=MATCH(lookup_value,INDEX(lookup_array,0,column_number),0)
You could do something like this:
Set findCell = ActiveSheet.Range("A:Z").Find(What:="term_to_search")
Will select a header based on your search term.
Set range = ActiveSheet.Range(findCell, findCell.Offset(DEF_MAX_ROWS, 0))
Set up a range which will search from that header down a whole column.
For column references beyond Z you might switch notation (Excel Options, Formulas, Working with formulas and check R1C1 reference style) and, assuming the value to be looked up is in 'A1' (R1C1) with the column number in 'A2' (R2C1) apply:
=MATCH(R1C1,INDIRECT("C"&R2C1,0),0)
to save some complexity in converting a string of two or three characters into the relevant column number.
Say we have a two dimensional array: B3:E17 and we wish to locate Happiness in the third column of that array.In G1 enter:
B3:E17
In G2 enter:
3
In G3 enter:
=ADDRESS(ROW(INDIRECT(G1)),COLUMN(INDIRECT(G1))+$G$2-1) & ":" & ADDRESS(ROW(INDIRECT(G1))+ROWS(INDIRECT(G1))-1,COLUMN(INDIRECT(G1))+$G$2-1)
This will display the address of that third column. Then in G4 enter:
=MATCH("Happiness",INDIRECT(G3),0)
For example:
You can specify a range in a formula using the INDIRECT function. So, for example, if you put the letter designation for the column you want to search in cell A75, you could use:
=MATCH("Value_To_Match", INDIRECT(A75 & ":" & A75), 0)
So, if the value in A75 is G, the string built up in the INDIRECT call is G:G, and the MATCH will look through column G for "Value_To_Match" and return the row number in which it's found.
Using this idea, you can put a formula into A75 that generates the column designation for the column you want to search. For example, if your column headers are all in row 1, and the header you want to search for is in A74, you can do:
=CHAR(MATCH(A74, 1:1, 0) + 64)
using the CHAR function to convert numbers into ASCII characters, so 65 becomes A, 66 becomes B, etc. Note that this will only work if you don't have columns past Z. You'd need a more fussy formula to do the right thing with AA, etc.
You can overcome the annoyances of dealing with column letters by using R1C1 notation instead, which you can activate by adding a second parameter of FALSE to the INDIRECT expression. Now, instead of specifying your column by a letter, you'll specify it using a number. This simplifies the column-finder in A75:
=MATCH(A74, 1:1, 0)
and also the INDIRECT expression in your overall MATCH:
=MATCH("Value_To_Match", INDIRECT("C" & A75, FALSE), 0)

Resources