VLOOKUP vs INDEX - excel

In Excel, I'm trying to do the following:
Where sheet1 column 1 = sheet2 column 2, return the value in sheet2 column D
I'm stumbling on how to do this as every example I've found seems to use the column index value of the sheet containing the formula. (i.e., sheet1)
I want: VLOOKUP(sheet1!A1,sheet2!A2:A11696,sheet2!4,FALSE)
I can only: VLOOKUP(sheet1!A1,sheet2!A2:A11696,4,FALSE)
After reading other threads, I see people seem to recommend using INDEX. So I tried
=INDEX(sheet2!A2:A11696, MATCH(sheet1!A1004,sheet2!D:D,FALSE))
This doesn't work either.

Your VLOOKUP only references one ccolumn, It should be 3. And start in Column B
VLOOKUP(sheet1!A1,sheet2!B2:D11696,3,FALSE)
The First Criterion is the what to lookup, sheet1!A1
The second is the range in which the value to find and the value to return is found. The first column of the range must be the column in which the criteria will be found. As per sheet1 column 1 = sheet2 column 2 that would then start the range in Column B.
And since the value you want in Column D Column D must be included in the range.
The Third is in which column of the range is the value. It is not the column number itself, but the relative column number, in this case it is the third column in the Range sheet2!B2:D11696.
The forth forces an exact match or relative match. FALSE forces an Exact Match.
If you are going to use an INDEX/MATCH then:
=INDEX(sheet2!D2:D11696, MATCH(sheet1!A1,sheet2!B2:B11696,0))
The MATCH part returns the relative row number where A1 is found in Column B on sheet two.
Then using this number in the INDEX it finds that relative row number in the range in Column D and returns that value.
The 0 in the MATCH() tells the Match to look for the exact match.

The INDEX/MATCH function pair should look like this.
=INDEX(sheet2!D:D, MATCH(sheet1!A1, sheet2!B:B, 0))

In a more generic sense, the INDEX/MATCH method is used as follows:
=INDEX(A:A, MATCH(B1, C:C, 0))
Where:
A:A = The row or column containing the value you need to find.
B1 = The value you are using to reference the index (location) of the value you're trying to find.
C:C = The row or column containing the value that matches B1. The size of this range should match the size of A:A, though it is not required.
0 = This just means "Match exactly". -1 would mean "match if B1 is less than C:C. 1 would mean "match if B1 is greater than C:C.

Related

Excel - Find matching values and copy different cell

I have 2 Excel spreadsheets and both sheets have a "Code" field and value that may or may not exist in both. In sheet1 and sheet2 there is also an "ID", i'm hoping that if the "ID" is populated in sheet1 and if the matching code exists in sheet2, a query can transfer the "ID" to sheet 2
SHEET1
|
SHEET2
I can find the matching values using vlookup but my issue is getting the ID field to populate
=VLOOKUP(A1,Sheet1!A:A,1,FALSE)
Instead: =VLOOKUP(A1,Sheet1!A:B,2,FALSE).
From Microsoft's help on Vlookup:
How to get started
There are four pieces of information that you will need in order to build the VLOOKUP syntax:
The value you want to look up, also called the lookup value.
The range where the lookup value is located. Remember that the
lookup value should always be in the first column in the range for
VLOOKUP to work correctly. For example, if your lookup value is in
cell C2 then your range should start with C.
The column number in the range that contains the return value. For
example, if you specify B2:D11 as the range, you should count B as
the first column, C as the second, and so on.
Optionally, you can specify TRUE if you want an approximate match or
FALSE if you want an exact match of the return value. If you don't
specify anything, the default value will always be TRUE or
approximate match.
Pay special attention to parameters 2 and 3.
Note that number 2 "The range where the lookup value is located" should be the full range where the first column of the range has the values to lookup and the last column of the range should contain the values you want to return. So your A:A only having one column, will only lookup and return values in column A. You want values returned from column B so it must be included as well, to become A:B.
Since column B is the second column in the lookup range of A:B then your third parameter will be 2 which leads to the vlookup at the top of this answer.
This is what you are doing:
VLOOKUP(A1,Sheet1!A:A,1,FALSE)
(I will only talk about Sheet1!A:A and 1)
You are looking into column A and from there you are taking column number 1 (which is column A).
What you should be doing, this this:
VLOOKUP(A1,Sheet1!A:B,2,FALSE)
Look into table, made up of columns A and (up to) B, you will automatically look into the first column, and you return the value you find in column number 2 (which is column B).

Lookup one cell in another sheet then return corresponding value

I have two sheets containing various columns in which two columns contains document number and prices. Now I want to match cell K3 (a document number ) of Sheet 1 within column D (all document numbers) of Sheet 2. If match exists, then i want the corresponding price mentioned in Column V to be returned.
This is the formula I've tried:
=VLOOKUP(K3,'Sheet1 (2)'!D2:D896,22,FALSE)
The VLOOKUP documentation is helpful here, especially points 2 and 3 which correspond to parts 2 and 3 of the formula.
The range where the lookup value is located. Remember that the lookup value should always be in the first column in the range for VLOOKUP to work correctly. For example, if your lookup value is in cell C2 then your range should start with C.
The column number in the range that contains the return value. For example, if you specify B2: D11 as the range, you should count B as the first column, C as the second, and so on.
So change the second D to V in your lookup range, and change the column to 19 instead of 22 - D is the 1st column, E the second and so on till V, the 19th column of the lookup range.
=VLOOKUP(K3,'Sheet1 (2)'!D2:V896,19,FALSE)
if VLOOKUP is not your thing, consider INDEX/MATCH.
=INDEX('Sheet1 (2)'!V:V,MATCH(K3,'Sheet1 (2)'!D:D,0))
=VLOOKUP(K3,Sheet1!D3:E8,2,FALSE)
In formula second last argument is the column number of values.

Excel - compare 2 lists [duplicate]

In Excel, I'm trying to do the following:
Where sheet1 column 1 = sheet2 column 2, return the value in sheet2 column D
I'm stumbling on how to do this as every example I've found seems to use the column index value of the sheet containing the formula. (i.e., sheet1)
I want: VLOOKUP(sheet1!A1,sheet2!A2:A11696,sheet2!4,FALSE)
I can only: VLOOKUP(sheet1!A1,sheet2!A2:A11696,4,FALSE)
After reading other threads, I see people seem to recommend using INDEX. So I tried
=INDEX(sheet2!A2:A11696, MATCH(sheet1!A1004,sheet2!D:D,FALSE))
This doesn't work either.
Your VLOOKUP only references one ccolumn, It should be 3. And start in Column B
VLOOKUP(sheet1!A1,sheet2!B2:D11696,3,FALSE)
The First Criterion is the what to lookup, sheet1!A1
The second is the range in which the value to find and the value to return is found. The first column of the range must be the column in which the criteria will be found. As per sheet1 column 1 = sheet2 column 2 that would then start the range in Column B.
And since the value you want in Column D Column D must be included in the range.
The Third is in which column of the range is the value. It is not the column number itself, but the relative column number, in this case it is the third column in the Range sheet2!B2:D11696.
The forth forces an exact match or relative match. FALSE forces an Exact Match.
If you are going to use an INDEX/MATCH then:
=INDEX(sheet2!D2:D11696, MATCH(sheet1!A1,sheet2!B2:B11696,0))
The MATCH part returns the relative row number where A1 is found in Column B on sheet two.
Then using this number in the INDEX it finds that relative row number in the range in Column D and returns that value.
The 0 in the MATCH() tells the Match to look for the exact match.
The INDEX/MATCH function pair should look like this.
=INDEX(sheet2!D:D, MATCH(sheet1!A1, sheet2!B:B, 0))
In a more generic sense, the INDEX/MATCH method is used as follows:
=INDEX(A:A, MATCH(B1, C:C, 0))
Where:
A:A = The row or column containing the value you need to find.
B1 = The value you are using to reference the index (location) of the value you're trying to find.
C:C = The row or column containing the value that matches B1. The size of this range should match the size of A:A, though it is not required.
0 = This just means "Match exactly". -1 would mean "match if B1 is less than C:C. 1 would mean "match if B1 is greater than C:C.

Excel Vlookup Across Different Sheet

I have a excel file with 2 work sheets. They look like this:
Sheet 1:
Sheet 2:
I want to look up the value of column A (sheet1) when matched with column A (sheet 2) copy the value of column B (sheet 2) to column B (sheet 1).
I know I have to use vlookup but I really have no idea where to start with this.
An example of the result:
VLOOKUP works by taking a square range of data, looking at the first column of that data for a match you specify, and then returning the value of that row a given number of columns to the right. For example, in your case, it would look as follows [for B2 in sheet1, copied down]:
=VLOOKUP(A2,'Sheet2'!A:B, 2, FALSE)
This takes the value from cell A2, then looks at column A on sheet2. If it finds a match, it returns the value on the 2nd column of the table [ie: column B]. If there is no match, it will return #N/A. The FALSE means that it doesn't assume your data is sorted [if it is, you can use VLOOKUP to take a 'next best' value if there is no match.

excel formula : Find uniques in one column depending on value of another column

I can do this manually but I'm sure there is a formulaic way to do this.
Here is the data :
Column-A Column-B Column-C
C Y
D
E Y
F
E Y
What I want to do is in 2 steps :
a.) Select all values in Column-A, where the corresponding value in Column-B is "Y".
b.) From the data selected from Column-A above, select only the unique values and put them in Column-C
c.) Hence the data in Column-C for the above data will be "C" & "E"
Any pointers ?
Here's one option assuming you have excel 2007
Put this formula in C1
=IFERROR(INDEX(A1:A5,MATCH("Y",B1:B5,0)),"")
then this one in C2 copied down
=IFERROR(INDEX(A$1:A$5,MATCH(1,INDEX((B$1:B$5="y")*(COUNTIF(C$1:C1,A$1:A$5)=0),0),0)),"")
You can do it in earlier versions but it requires some longer formulas to ensure that you don't get error values once valid matches are exhausted
Explanation:
Formula 1 uses MATCH to find the position of the first "y" in B1:B5, then INDEX returns the relevant value from A1:A5. If your columns were the other way round you could use VLOOKUP, INDEX/MATCH is a standard way to do a "left lookup".
Formula 2 uses MATCH to find the position of the first row where 2 conditions are satisfied, B1:B5 = "y" and A1:A5 <> a value already found. The values already found are in column C above so the COUNTIF function looks at the cells above and does a count for each value in column A within that range above (which expands as you drag the formula down) - a count of zero means that that value hasn't already been selected. Once MATCH identifies the row number INDEX takes the value from that row in column A.

Resources