RE: Excel vlookup
Hi Kingsley, Thank you for your post, after a bit of consideration I think that the following rambling explanation might be of help:
Question: I'd like to link selected contents of a table from one spreadsheet to another, but I would like the function to copy only the rows in which the value in first column equals 'X' .
If you've been using Excel for a while, you have invariably found someone who talks about using INDEX() and MATCH() instead of VLOOKUP. Give me a couple of minutes and I will try to explain them in simple English.
A 30 second review of VLOOKUP;
Say you have a table of employee records. The first column is an employee number, and the remaining columns are various pieces of data about the employee. Any time you have an employee number in the worksheet, you can use VLOOKUP to return a specific datum about the employee. The syntax is VLOOKUP(value,data range,col no.,FALSE). It says to Excel, "Go to the data range. Find a row that has (value) in the first column of the data range. Return the (col no.) the value from that row.
When the key field is to the right of the data you want to retrieve, VLOOKUP will not work.
One common solution is to temporarily insert a new column A, copy the column of names to the new column A, populate with VLOOKUP, Paste Special Values, then delete the temporary column A.
I am going to suggest you take a challenge to use a different method;
So, let me break it down into two pieces.
First, there is the INDEX() function. This is a horribly named function. When someone says "index", it does not conjure up anything in my mind that is similar to what this function does. Index requires three arguments. =INDEX(data range, row number, column number). In English; Excel goes to the data range and returns you the value in the intersection of the (row number) the row and the (column number) the column. Hey, that’s pretty straightforward, right? =INDEX($A$2:$C$6,4,2) will give you the value in B5.
Applying INDEX() to our problem, you can figure, that to return the employee number from the range, you would use this: =INDEX($A$2:$A$6,?,1). Actually, this piece of it seems so trivial that it seems useless. But, when you replace the question mark with a MATCH() function, you have the solution.
Here is the syntax: =MATCH(Value, Single-column data range, FALSE). It tells Excel, "Search the data range and tell me the relative row number where you find a match for (data).
So, to find which row has the employee in A10, you would use =MATCH(A10,$B$2:$B$6,FALSE). Yes, this is more complex than Index, but it should be quite easy for a VLOOKUP pro. If A10 contains "Smith, John" then this MATCH will return that he is in the 3rd row of the range B2:B6.
There it is - the MATCH() function tells the Index function which row to look in - you are done. Take the Index function, replace your question mark (x) with the MATCH function, and you can now do the equivalent of VLOOKUPs when the key field is not in the left column. Here is the function to use:
=INDEX($A$2:$A$6,MATCH(A10,$B$2:$B$6,FALSE),1)
Write it out: First the explanation for MATCH(). Below that the explanation for INDEX(). Then draw a funnel shape between the two to indicate that the MATCH() function drops in to the 2nd argument of the INDEX() function. The first few times I had to do one of these, I was tempted just to slam a new temporary column A in there, but went through the pain of doing it this way instead. It is faster, and requires less manipulation. So, the next time you are wishing you could put a negative number in the VLOOKUP function, try this strange combination of INDEX and MATCH to solve your problems.
Now that you have met INDEX and MATCH could also nest the MATCH function in a VLOOKUP;
The VLookup formula returns data from any column you choose in the data table, simply change the number of the column in the third argument.
The final result is a nested formula such as this:
=VLOOKUP (A2, Data, MATCH(A1, Row 1, 0))
I hope that has helped. if so please click the resolved link, regards Pete