I\'m new to the excel formula, so I don\'t know all the functions. I\'m trying to create a formula using Vlookup or something akin to it for my inventory excel sheet.
<For future reference, looking up values can be done in several ways (e.g.: VLOOKUPand HLOOKUP), however a very powerful combination can be made using INDEX and MATCH, being at least as fast as other functions and at best much faster.
INDEX
The INDEX function function returns a value or the reference to a value from within a table or range and has got the following parameters:
So the syntax would look like: =INDEX(RangeOfCells,RowIndex,[ColumnIndex])
MATCH
The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range. It has got the following parameters:
So the syntax would look like: =MATCH(LookupValue,LookupArray,[MatchType])
INDEX + MATCH
Let's imagine a simple dataset in Sheet1 like the following:
| Header1 | Header2 | Header3 | Header4 |
|---------|---------|---------|---------|
| ID1 | A | Val1 | Month1 |
| ID2 | B | Val2 | Month2 |
| ID3 | C | Val3 | Month3 |
| ID4 | D | Val4 | Month4 |
| ID5 | E | Val5 | Month5 |
And the following setup to search for a value in Sheet2:
| Header1 | Header2 | Header3 | Header4 |
|---------|---------|---------|---------|
| ID3 | | | |
Now if you are interested in the value of Header2 up to Header4 by looking up a specific value under Header1 you can apply the following technique in B2 and drag right.
=INDEX(Sheet1!$B:$D,MATCH($A2,Sheet1!$A:$A,0),COLUMN(A1))
The result will look like:
| Header1 | Header2 | Header3 | Header4 |
|---------|---------|---------|---------|
| ID3 | C | Val3 | Month3 |
If you take into consideration the above about INDEX and MATCH you can see that I gave INDEX it's required array of cells (1st parameter), used MATCH to return a row index number (2nd parameter) and have utilized the COLUMN function along with a relative cell reference to return the column index number (3rd parameter).
The MATCH function has been given a lookup value (1st parameter), a lookup array (2nd parameter) and I have used match type 0, which tells the function to look for an exact match.
VLOOKUP
In this specific case it would have been possible to utilize the VLOOKUP function. But I'll try to set out why I would prefer the INDEX + MATCH combination:
VLOOKUP gives you little flexibility as the lookup value must sit in the left-most column of your lookup matrix, whereas INDEX gives you the option to return any column through the third parameter.VLOOKUP is the more popular option, INDEX + MATCH is the faster option. If you go for speed, then use this!Further notes:
While this was just a simple breakdown of how you could use the combination of INDEX + MATCH, there are a few more things to consider:
$ sign). Utilize this technique to be able to drag a formula to the right, left, bottom or top.INDEX and MATCH is something that will appear as a lifesafer much more often in many ways :)MATCH might return an error when the lookup value simply isn't found. This is something to consider when you see any #N/A error. A workaround is a ISNA or IFERROR function within the formula.I hope that gets you started! Check the links I included for some more in-depth information.