You are here:

Excel/Understanding a VLOOKUP

Advertisement


Question
I am using excel 2013.

Can you help you help me understand this formula? It's in a workbook I was given and makes reference to two other workbooks, one being a workbook complete with several different references lookups of sheets for locations (Office name),(city etc), sublocations like (Office 121, HR Office etc) that have all names and then IDs. The other sheet (Laptop Inventory) is the old sheet that is in the process of being updated to the new workbook (the one this formula is in). Basically I know the formula pulls in data from the old workbook and matches it with the locations, sub locations and IDs in the reference workbook. I understand that anything left blank or error message is then updated to say "BLANK". I understand the vlookup part I think and have finished updating all the data in the reference and old sheet so my new workbook is complete.

I want to replicate this formula for another inventory list for PCs so I will be using the reference workbook (with my updates) and also an old workbook and the brand new one to pull it all together. Can you help me understand this formula so I know where and when to use it? I've never seen ISERROR before and I don't understand why there's a second vlookup and what it's purpose is.

=IF(ISERROR(VLOOKUP('[Laptop Inventory LaptopComs.xlsx]Sheet1'!G2,[LookupReferences.xlsx]LOCATIONSUB!$A:$B,2,FALSE)),"BLANK",(VLOOKUP('[Laptop Laptop PrintComs.xlsx]Sheet1'!G2,[LookupReferences.xlsx]LOCATIONSUB!$A:$B,2,FALSE)))

Thaank you

Answer
shona,

So I understand that you are not asking about how vlookup works, but how it is used in the overall formula.

=IF(ISERROR(VLOOKUP('[Laptop Inventory LaptopComs.xlsx]Sheet1'!G2,[LookupReferences.xlsx]LOCATIONSUB!$A:$B,2,FALSE)),"BLANK",(VLOOKUP('[Laptop Laptop PrintComs.xlsx]Sheet1'!G2,[LookupReferences.xlsx]LOCATIONSUB!$A:$B,2,FALSE)))

When you do a vlookup, if the item being looked up is not found, then Vlookup returns the #N/A error.  The author of the formula preferred to return BLANK rather than return #N/A.  So the formula executes the first vlookup and if it comes back with an error, then the overall formula returns the string BLANK.   Now lets look at the two vlookup formulas

VLOOKUP('[Laptop Inventory LaptopComs.xlsx]Sheet1'!G2,[LookupReferences.xlsx]LOCATIONSUB!$A:$B,2,FALSE)
VLOOKUP('[Laptop Laptop PrintComs.xlsx]Sheet1'!G2,[LookupReferences.xlsx]LOCATIONSUB!$A:$B,2,FALSE)

So this is pretty unusual.  In the first Vlookup, you lookup a value from G2 of Sheet1 of one workbook.  If that fails, then it returns blank.  But it doesn't fail, it then executes the second vlookup with lookups a value from g2 of sheet1 but from a different workbook.  If G2 will contain the same value to be looked up in both instances, then if the first vlookup is successful, then the second Vlookup would be used to actually return the value.  This is the usual usage for this construct.  Use the first vlookup to see if the vlookup will be successful.  If not successful return BLANK.  If it is successful, then perform the same vlookup again to actually return the value.  

In your case, since you are looking up values from separate workbooks but against the exact same table and parts of that table, then it really isn't clear why you are using G2 from separate workbooks.  But perhaps you find the first value being looked up it does guarantee that the second value will be found.  Then the second vlookup returns the desired value.

--
Regards,
Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.