When do we use vlookup




















That's it! When you press Enter, it should give you the answer, which is 9. Let's take a look at how this formula works. When it finds "Photo frame", it moves to the second column to find the price. As we mentioned earlier, the price needs to be to the right of the item name.

In the next example, we'll show how to avoid this by using a cell reference. Are you ready for a slightly more advanced example? We're going to make a couple of changes to the spreadsheet to make it more realistic. But in the real world, you'll usually use a cell reference instead. Then, we can simply type a new item name into E2 to find any product we want.

We've also added a third column that has the category for each item. This will give us the option of finding the price or category. Here's what the spreadsheet looks like so far:. Our formula will be similar to the previous example, but we'll need to change the first three arguments. Let's start by changing the first argument to a cell reference make sure to remove the quotation marks :. Let's throw in one more complication.

What happens if your sheet name contains spaces? If there are spaces in the sheet name, you will need to change the formula further. Let's assume that the table is on a Sheet called "Test Sheet" in the range A1:B6, now we need to wrap the Sheet name in single quotes as follows:.

For example, if you wanted to have the table portion of the VLOOKUP formula be from an external workbook, we could try the following formula:. Now it is important for us to cover one more mistake that is commonly made. When people use the VLOOKUP function, they commonly use relative referencing for the table range like we did in some of our examples above. This will return the right answer, but what happens when you copy the formula to another cell?

The table range will be adjusted by Excel and change relative to where you paste the new formula. Let's explain further Since your table is found in the range A1:B6 and not B2:C7, your formula would return erroneous results in cell H2.

To ensure that your range is not changed, try referencing your table range using absolute referencing as follows:. This is a great way to spruce up your spreadsheet so that you don't see traditional Excel errors.

Frequently Asked Questions. While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy. Absolute ranges are pretty ugly looking, so can make your VLOOKUP formulas a lot cleaner and easier to read by replacing absolute references with named ranges, which are automatically absolute. For example, in the employee data example above, you can name the input cell "id" and then name the data in the table "data", you can write your formula as follows:.

Not only is this formula easier to read, but it's also more portable, since named ranges are automatically absolute. This is because hard-coded column index values don't change automatically when columns are inserted or deleted. In this example, the lookups for Rank and Sales were broken when a new column was inserted between Year and Rank. Year continues to work because it is on the left of the inserted column:. If you're getting data from consecutive columns, this trick lets you set up one VLOOKUP formula, then copy it across with no changes required.

For the first formula in cell C3, COLUMN by itself will return 3 because column C is third in the worksheet so we simply need to subtract one, and copy the formula across:. Taking the above tip one step further, you can use MATCH to look up the position of a column in a table and return a fully dynamic column index.

An example would be looking up sales for a salesperson in a particular month, or looking up the price for a particular product from a particular supplier. It may seem counterintuitive, but wildcards let you do an exact match based on a partial match :.

If you like, you can adjust the VLOOKUP formula to use a built-in wildcard, like the example below, where we simply concatenate the value in H3 with an asterisk. They give you an easy way to create a "lazy match", but they also make it easy to find the wrong match.

In one way, this is useful because it tell you definitively that there is no match in the lookup table. To trap this error and display a "not found" message instead of the error, you can simply wrap the orignal formula inside of IFERROR and set the result you want:. Here is the formula:. If you are simply retrieving numbers as text from a column in a table, it doesn't matter.

In the following example, the ids for the planet table are numbers entered as text , which causes VLOOKUP to return an error since the lookup value is the number To solve this problem, you need to make sure the lookup value and the first column of the table are both the same data type either both numbers or both text.

One way to do this is to convert the values in the lookup column to numbers. An easy way to do this is to add zero using paste special. If you don't have easy control over the source table, you can also adjust the VLOOKUP formula to convert the lookup value to text by concatenating "" to the value like so:.

If you've ever built a series of nested IFs, you know that they work fine, but they require a bit of parentheses wrangling. You also have to be careful about the order you work in, so as not to introduce a logical error. For example, a common use of nested IFs is to assign grades based on a score of some kind. In the example below, you can see a formula has been build with nested IFs to do just that, using the grade key at the right as the guide.

This works fine, but note that both the logic and the actual scores are baked right into the formula. If the scoring changes for any reason, you'll need to carefully update one formula then copy it down the entire table. A nice bonus of this approach is that both the logic and the scores are built right into the grade key table.



0コメント

  • 1000 / 1000