Excel VLOOKUP and HLOOKUP Functions

A comprehensive guide to these powerful functions in Excel

The LOOKUP functions can be used to look up data in an Excel list or Excel database, saving a lot of time and potential error when comparing two lists of data. You have two LOOKUP functions, Excel VLOOKUP and the HLOOKUP. The only difference between the two functions is that the VLOOKUP  is used for vertical lists or databases and the HLOOKUP is used for horizontal lists or databases.

The Excel VLOOKUP function has 4 arguments Lookup_value, Table_array, Col_index_num, and Range_lookup.  We will use an example based around staff salary calculations to explore each of these VLOOKUP arguments.

lookup1
Vlookup figure 1

The Lookup_value is the value you want to look up in the Excel database or Excel list. In the example (figure 1) the Lookup_value is in B3. By entering a staff id in B3 the VLookup function can look up a value in the list with staff data. The Table_array is the data range and the value you want to look up must be in the first column of the Table_array. Col_index_num is the column number inside the Table_array you want the function to extract the data from and display it in the cell with the Vlookup function.

You have two options for the argument Range_lookup. If you enter false or 0 (zero) the function will display #N/A if it cannot find the Lookup_value in the Excel list or Excel database. It will only display a result if there is a perfect match between the Lookup_value and a value in the first column in the Table_array. If you enter true or 1 the function will display a result if there is a perfect match between the Lookup_value and a value in the first column in the Table_array and if there is no perfect match it will display the nearest lowest value. In other words if you in the example enter 12 in B3 the function will return “Gwendy” because 10 is the nearest lowest value to 12. The first column in the Table_array must be sorted in ascending order if you are using True or in Range_lookup.

Lookup nearest lowest value

In the example (figure 2) the VLOOKUP function is used to look up the raise based on current salary. The Lookup_value is the salary in F3. The Table_array is the range $I$3:$J$10 (the lookup table). The range is absolute (the dollar signs) to be able to copy down the function without changing the range. The Col_index_num is 2. The raise percentage is in column 2 in the Table_array. The Range_lookup is trueTrue because you want the function to return a result also if there is no perfect match. If the salary the Look_up value is £35,850.00 the function cannot find a perfect match in the Table_array but the nearest lowest value is 35,000 so the function will return 4%.

Lookup nearest lowest value figure 2
Lookup nearest lowest value figure 2

Compare two lists using VLOOKUP

You can use the Excel VLOOKUP and HLOOKUP to compare two lists or Excel databases. The Lookup_value in this example (figure 3) is the staff id (it must be a unique value) in the first Excel list or database. The Table_array is the staff id range in the second list or database. Make the array absolute by using dollar signs around the cell references ($I$3:$I$9) again to be able to copy down the function without changing the range cell references. In the argument Range_lookup enter false because you only want a perfect match.

Compare two lists using Vlookup
Compare two lists using Vlookup figure 3

Copy down the function and if the function displays #N/A then it is because you do not have the record in the second Excel list or Excel database.

Compare lists figure 4
Compare lists figure 4

Dynamic Col_index_num using numbered columns

If you need to look up information in many columns you can refer to the columns using relative cell references in Col_index_num. this will save you some time instead of entering the column number in each Excel VLOOKUP or HLOOKUP  function. In the example (figure 5) the column numbering is in row 4. To get the first name in C3 the cell reference C4 is entered in Col_index_num. Copy the function across and the function will pickup the Col_index_num across from row 4. Now it is very easy and less time consuming to add or remove columns from the array and also very easy to change the order of the information you want in row 3. You just need to change the numbering in row 4.

Lookup dynamic col numbers figure 7
Lookup dynamic col numbers figure 5

Dynamic Col_index_num using nested If functions 

You can use nested If functions to make Col_index_num dynamic. In the example (figure 6) the bonus is based on the department and bonus category group. If the staff member works in the sales department and is in the bonus category group 1 the VLOOKUP function must return 3%, bonus category group 5 it must return 4%, and in bonus category group 10 5%. By nesting two If functions in Col_index_num you can use the information in column G the bonus category column to get the VLOOKUP function to return the right column from the Table_array

Lookup_value is the department in E3. The Table_array is the range $J$3:$M$7. Type IF(G3=”Group 1″,2,IF(G3=”Group 5″,3,4)) in Col_index_num. In the first If function you want to find out if G3 equals “Group 1”. If it is true you want the VLOOKUP function to look up the bonus from column 2. If it is not true you want the second If function to find out if G3 equals “Group 5”.  If it is true you want the VLOOKUP function to look up the bonus from column 3. If it is not true you want the VLOOKUP function to look up the bonus from column 4. In Range_lookup type false because you only want to look up a perfect match.

Dynamic lookup nested ifs figure 6
Dynamic lookup nested ifs figure 6

Lookup data in more than one Excel list or Excel database using the Indirect function and range names

In the example (figure 7) there are 3 tables. The data range in each table has a range name Finance, Production, and Sales. In the example you want to lookup staff id 3 from the sales department. The range name is entered in C19 and the staff id in E19. B22 is linked to C19. Lookup_value is B22 (the staff id). The Indirect function is nested in Table_array. The Indirect function will see the content of C19 as a range name. Col_index_num is the column number inside the Table_array you want  the function to extract the data from and display it in the cell with the VLOOKUP function. In Range_lookup type false because you only want to lookup a perfect match.

Lookup data in multiple lists figure 7
Lookup data in multiple lists figure 7

Lookup data in more than one Excel list or Excel database using the Choose function

The Choose function can also be useful to lookup data in two or more tables. In the example (figure 8) the VLOOKUP function looks up the commission rate in the two commission tables to the right. The Choose function gets the table number from column D.

lookupchoose
Vlookup with choose function figure 8

Lookup data in Excel list or database using the Match function to return the information from the right column in the array

In the example below (figure 9) a VLOOKUP function in C21 is used to lookup the sales for a specific sales person (Richard) for as specific month (March). The Match function can find the position of a value or text string in a row or column and this information the VLOOKUP can use to get the Col_index_num. In the example the Match function return 4 to the VLOOKUP.

vlookupmatch
Vlookup with the Match function figure 9

Lookup and summarize a column using the Sumproduct function

In the example (figure 10) a month needs to be summarized. The Sumproduct function can summarize an array. In C10 the month which needs to be summarized is entered. The HLOOKUP is nested inside the Sumproduct function.  Row_index_num is in this example not only one row but five rows (row 2 to 6). The curly brackets {2,3,4,5,6} tells Excel that it is not only one row but a number of rows (an array).

Hlookup and summarize column
Hlookup and summarize column figure 10

Lookup and summarize a row using the Sumproduct function

In the example (figure 11) 6 months for a specific sales team needs to be summarized. Again as the example above the Sumproduct function can summarize the array. In C11 the name of the sales team is entered. The Excel VLOOKUP is nested inside the Sumproduct function.  Col_index_num is many columns (column 2 to 7). Again the curly brackets {2,3,4,5,6,7} is used to tell Excel that it is not only one columns but a number of columns (an array).

Vlookup and summarize a range figure 9
Vlookup and summarize a range figure 11

Summary – VLOOKUP function

We have covered some detailed aspects of VLOOKUPs and how useful they can be when working with lists and databases. Other instances where you might use VLOOKUPS and HLOOKUPS

  • Search Engine Marketing – matching keyword terms, PPC rates, etc
  • Sales commission rates – looking up sales for specific rep and applying commission
  • Product price/description – looking up a product code to return the price and description
  • Stock market data – looking up stock tickers and displaying trading information, stock price, movement

Resources

VLOOKUP in practice

How to use an Excel VLOOKUP function in VBA

VLOOKUP tutorial

Video – Excel Vlookup – Finding an Exact Match

Get back control of your Excel spreadsheets

Poor Excel skills are costing UK businesses millions in lost revenue. According to an article in the Financial Times more than half of financial service groups have “poorly applied or no controls for managing business critical spreadsheets”.

The article blamed losses in part due to “avoidable errors in MS spreadsheets”. So, what could thousands of UK businesses do differently?

THE PROBLEM: “Fat finger” input mistakes

fingers on keysExcel spreadsheets are an integral part of many UK businesses. Used for anything from accounting to CRM, they are a system with a low barrier to entry. Business users start one up and start recording data.

Mistakes in Excel, however, can often be harder to spot than those in other MS applications. Though error messages will appear for misspelt formulae, they won’t pick up incorrectly populated fields. Help is at hand though, here’s how to reduce the risk of “fat finger” input mistakes:

THE SOLUTIONS:

Data Validation

All but eliminate the room for error with data validation formatting. This Excel feature will allow you to:

  • Make a list of possible entries, restricting the values allowed in a cell
  • Create an automated message when incorrect data has been inputted
  • Set a range of numeric values that can be entered into cells
  • Determine if an entry is valid based on calculations of other cells

By restricting the values allowed in a cell and setting formatting properties, you’ll have tighter control over editing functions and are likely to experience fewer cases of fat finger mistakes. Sure, these will still be made, but they’ll be visible right away.

To view a step by step guide of how to tutorials, visit the Microsoft Office support centre.

data validation

VLOOKUP

vlookup

If there are two tables of data that need to be cross-referenced, or you need to pull data from one table to another, don’t copy and paste. VLOOKUP is arguably the most useful function in Excel, and mastery of it will ensure that exactly the right data ends up in exactly the right place.

IFERROR

Pre-empt the fact that your formulas may run into errors. Assume they will and use the IFERROR function in Excel to provide a ‘catch’ scenario – replacing the error with a blank or zero for instance.

IFERROR’s are a quick and easy way to see null values, often a result of human error, whether that’s a formula, data entry or another error.

iferror

THE PROBLEM: No audit trail

With poor controls over quality control being blamed for huge monetary losses, auditing things like who has edited a workbook can be a useful way of keeping track of minor changes, that could have major consequences for your business. Excel offers a number of solutions to best fit your company’s skills set.

THE SOLUTIONS:

Workbook tracking

Quickly and simply see the changes made to your shared workbooks by tracking changes. This is great for organisations with multiple editors, allowing each author to see the additions and overwritten fields upon reopening the spreadsheet.

Excel offers three methods of workbook tracking:

  • On-screen highlighting

A great way to see changes quickly, with edited boxes highlighted in a different colour for each user. Hold the cursor over the changed cell to see a brief description of the edit. It’s ideal for at a glance reviewing or for workbooks with few changes.

On screen highlight

  • History tracking

Excel can produce a separate history worksheet that provides a list of change details which you can filter and search for. This method is ideal for worksheets that have incurred a series of changes.

  • Reviewing of changes

If you’re evaluating comments from other users, this method is especially useful. Excel can step you through the changes made in sequence so that you can decide whether to accept or reject the amendment.

Utilising Excel systems

You can also use Excel systems as a way of preparing reports or standardising systems in more detail.

Creating reports using PivotTables

There’s no faster or more convenient way to generate dynamic reports. Better still you can build controls so end users can manipulate the results with ease.

pivottables in excel

Automation with macros and VBA

Performing repeated tasks in Excel can be tedious, which in turn can lead to laziness and human error. Macros capture repetitive tasks for easy playback.

The language that feeds macros is VBA. It’s a programming language that sits alongside Excel. It allows you to program and automate processes and while the learning curve is steep, it opens up the possibilities in Excel exponentially. The amount of human error reduced and time saved is staggering.

Conclusion

In training and consulting scenarios we have seen spreadsheets with errors and gaps in them that are waiting to be exploited. But with just an hour or two’s education we have been able to transform leaky models and flabby formulas into watertight, lean applications.

We’ve been training Excel for years and are proud of our 98%+ recommendation rate, delivering value with every course. Here’s what a representative of Credit Suisse had to say about an Excel Advanced course:

“There were functions in Excel that have always been there until today I had no idea what purpose they served. The trainer was very informative, knowledgeable, pleasant to work with and above made the session very well run.”

Anyone concerned that their spreadsheets are the weak point in their projections should put some research into Excel training, and stop financial losses today.

Intrigued? Get in touch with Best STL today to discuss your training needs. Our Advanced Excel Courses London are a fantastic way of getting acquainted with the higher functions of MS Excel.