VLOOKUP Hacks. 5 Ways to Get More Use from VLOOKUP Excel University ALL RIGHTS RESERVED

Similar documents
VLOOKUP vs. SUMIFS. Battle of the Excel Heavyweights. made with

Table of Contents. 1. Cover Page 2. Quote 3. Calculated Fields 4. Show Values As 5. Multiple Data Values 6. Enroll Today!

Lecture-14 Lookup Functions

Learn a lot beyond the conventional VLOOKUP

2. In Video #6, we used Power Query to append multiple Text Files into a single Proper Data Set:

Excel & Business Math Video/Class Project #33 VLOOKUP Function for Incentive Pay: Commissions and Piecework

Advanced Formulas and Functions in Microsoft Excel

My Top 5 Formulas OutofhoursAdmin

Excel Tips for Compensation Practitioners Weeks 9-12 Working with Lookup Formulae

Vlookup for dummies two sheets vlookup

Key concepts through Excel Basic videos 01 to 25

How to use the Vlookup function in Excel

EVALUATION COPY. Unauthorized Reproduction or Distribution Prohibited EXCEL ADVANCED

Top 15 Excel Tutorials

Intermediate Excel Training Course Content

Formulas, LookUp Tables and PivotTables Prepared for Aero Controlex

Light Speed with Excel

1.a) Go to it should be accessible in all browsers

Excel Intermediate. Click in the name column of our Range of Data. (Do not highlight the column) Click on the Data Tab in the Ribbon

Chapter 3: The IF Function and Table Lookup

Excel VLOOKUP. An EMIS Coordinator s Friend

Vlookup and Sumif Formulas to assist summarizing queried data

Intermediate Excel 2013

Advanced formula construction

MICROSOFT EXCEL 2000 LEVEL 3

3 Excel Tips for Marketing Efficiency

Become strong in Excel (2.0) - 5 Tips To Rock A Spreadsheet!

IF & VLOOKUP Function

VLOOKUP() takes three mandatory parameters and one default/optional parameter:

Instructions on Adding Zeros to the Comtrade Data

DOWNLOAD PDF MICROSOFT EXCEL ALL FORMULAS LIST WITH EXAMPLES

If Statements, For Loops, Functions

MS Excel How To Use VLOOKUP In Microsoft Excel

Excel Intermediate

Creating Custom Financial Statements Using

Excel Formulas 2018 Cindy Kredo Page 1 of 23

1.7 Limit of a Function

Excel Flash Fill. Excel Flash Fill Example

DESCRIPTION 1 TO DEFINE A NAME 2. USING RANGE NAMES 2 Functions 4 THE IF FUNCTION 4 THE VLOOKUP FUNCTION 5 THE HLOOKUP FUNCTION 6

Programs for American Fidelity WorxTime

Excel Intermediate

MIS 0855 Data Science (Section 006) Fall 2017 In-Class Exercise (Day 18) Finding Bad Data in Excel

1. NORM.INV function Returns the inverse of the normal cumulative distribution for the specified mean and standard deviation.

Excel 2. Module 2 Formulas & Functions

QUICK EXCEL TUTORIAL. The Very Basics

MICROSOFT EXCEL 2003 LEVEL 3

Excel: Tables, Pivot Tables & More

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Creating If/Then/Else Routines

ADVANCED EXCEL: LOOKUP FUNCTIONS

MODULE VI: MORE FUNCTIONS

Using GitHub to Share with SparkFun a

(Python) Chapter 3: Repetition

Watch the video below to learn more about number formats in Excel. *Video removed from printing pages. Why use number formats?

2 A little on Spreadsheets

Microsoft Office Excel 2007: Advanced Unit 02 - Lookups and Data Tables

MITOCW ocw f99-lec07_300k

Excel as a Tool to Troubleshoot SIS Data for EMIS Reporting

Customer details are included on a separate worksheet (Customer Look Up) Item details are included on a separate worksheet (Item Look Up)

Microsoft Excel 2010 Training. Excel 2010 Basics

Part II Composition of Functions

EXCELLING WITH ANALYSIS AND VISUALIZATION

How to Improve Your Campaign Conversion Rates

What is a VLOOKUP? Source

MICROSOFT EXCEL 2002 (XP): LEVEL 3

Error Vba Code For Vlookup Function In Excel 2010

Again, you can also use your mouse cursor to click-and-drag highlight a range of cells, or use Control + Click to handpick individual cells.

First-Order Translation Checklist

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

Excel Basics: Working with Spreadsheets

Excel 2010 Formulas Not Working In 2003 >>>CLICK HERE<<<

Excel: Linking sheets and summary sheets (Mac OS)

Pivot Table Project. Objectives. By the end of this lesson, you will be able to:

Intro. Scheme Basics. scm> 5 5. scm>

MICROSOFT EXCEL VERSIONS 2007 & 2010 LEVEL 3. WWP Learning and Development Ltd Page 1

Microsoft Excel Lookup Functions - Reference Guide

Excel Shortcuts Increasing YOUR Productivity

Microsoft Office Excel Training

DecisionPoint For Excel

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

Excel Tips. Contents. By Dick Evans

EXCEL AS BUSINESS ANALYSIS TOOL. 10-May-2015

What if Analysis, Charting, and Working with Large Worksheets. Chapter 3

Introduction to Programming

Create your first workbook

Course contents. Overview: Goodbye, calculator. Lesson 1: Get started. Lesson 2: Use cell references. Lesson 3: Simplify formulas by using functions

Excel 2010 Functions. 4/18/2011 Archdiocese of Chicago Mike Riley

CIO 24/7 Podcast: Tapping into Accenture s rich content with a new search capability

Introduction to Access 97/2000

Microsoft Excel 2007

Comparing and linking tables of data using VLOOKUP

EMIS - Excel Reference Guide

Four Numbers Functions Everyone Should Master

Lesson 3: Logic and Reference Functions

What is a spreadsheet?

Slide 1 CS 170 Java Programming 1 Multidimensional Arrays Duration: 00:00:39 Advance mode: Auto

Financial Reporting Using Microsoft Excel. Presented By: Jim Lee

EXCEL + POWERPOINT. Analyzing, Visualizing, and Presenting Data-Rich Insights to Any Audience KNACK TRAINING

SPRITES Moving Two At the Same Using Game State

(Refer Slide Time 6:48)

Transcription:

5 Ways to Get More Use from VLOOKUP ALL RIGHTS RESERVED

VLOOKUP Hack #1: Sort Order Issue VLOOKUP Hack #1 helps address the sort issue. Sort issue? Yes, and the sort issue has confuzzled many an Excel user over the years. Let s Dig In! Let s say we wanted to use VLOOKUP to retrieve an account name based on the account number from a chart of accounts. name is in the second column, we could use something like this in C7: =VLOOKUP(B7,Table1,2)\ When the table is sorted in ascending order by the lookup column, the AcctNum column, you get the expected result. For example, if the AcctNum is 1002, the VLOOKUP function above returns the expected account name, Savings, as shown in C7 below. Assuming the lookup value is B7, the lookup range is Table1, and the account

But, if the table get sorted by AcctName instead, we get an unexpected result, as shown below. Wait, what? 1002 is not Checking account, yet, that is what VLOOKUP returns is it broken? Is the formula wrong? What s up? Do I have to sort by the lookup column? What is going on here?

These questions all bring us to our first hack! So, the VLOOKUP formula above is written like this: =VLOOKUP(B7,Table1,2) You will notice that 3 arguments are defined, B7, Table1, and 2. But, here is the hack: there is an optional 4th argument! When the 4th argument is omitted, as in the formula above, it takes on a default value. So, we need to unpack this mysterious 4th argument to understand what is happening. The 4th argument controls the behavior of VLOOKUP in a couple of key ways, including, as you may suspect, the sorting requirement. Officially, the 4th argument is called the range_lookup argument. Practically, it tells Excel whether you are looking for an exact matching value, or, a value between a range of values. It is a Boolean argument, so it expects a TRUE or FALSE value. (Alternatively, you can use 0 instead of FALSE and any non-zero number instead of TRUE.) TRUE means you are looking for a value between a range of values, and FALSE means you are looking for an exact matching value. I ll expand this idea more later on, but for now, I want to stay focused on the sort issue.

When the 4th argument is TRUE, the data must be sorted in ascending order to return an accurate result. However, when the 4th argument is FALSE, the data need not be sorted any order is fine. So, when the 4th argument is TRUE, you may get an unexpected result if the data is not sorted in ascending order by the first column in the range. And, that is exactly what we saw above. We got an unexpected result. Instead of 1002 returning Savings, it returned Checking account. But, if we inspect the formula, we can see that we did not specify TRUE or FALSE for the 4th argument. We simply omitted it. Here is the key: when omitted, the 4th argument is TRUE. That means that when we write a VLOOKUP, and don t specify the 4th argument, it defaults to TRUE. When the data is not sorted in ascending order by the first column, you may get unexpected results. That means, sort order matters! So, we can resolve the issue by using FALSE (or 0) as the 4th argument, as shown below. =VLOOKUP(B7,Table1,2,FALSE) With that update to our formula, it returns Savings, as expected:

So, remember this: when the 4th argument is TRUE or omitted, the lookup range must be sorted in ascending order by the first (lookup) column to return an accurate result. But, when the 4th argument is FALSE (or 0), the data does not need to be sorted. VLOOKUP Hack #2: Range Lookups In the first VLOOKUP hack, we talked about how the 4th argument impacts the sort order. But, there is more to uncover about this 4th argument. So far, we understand that the 4th argument tells Excel whether we are looking for a value between a range of values or an exact matching value. Its official name is range_lookup, and now it is time to dig into what it actually means. When the 4th argument is TRUE, or omitted, it tells Excel to perform a range lookup. What exactly is a range lookup? It means you are looking for a value between a range of values. The fastest way to explain this is with an example and a picture.

Let s suppose the sales manager created a sales incentive program for the month. He would like you to pay a bonus amount to the sales reps based on their sales for the month. He then provides you with the following table: When you are doing this manually, you aren t looking for an exact matching sales amount. You are looking for a sales amount that falls between a start and end point. That is EXACTLY what the 4th argument means! That is a range lookup. If a salesperson had sales of 1,200 for the month, you would easily find the bonus amount of 50. If a salesperson had sales of 12,345, you would be able to determine the bonus amount is 500. So, when the 4th argument is TRUE, you are telling Excel to perform a range lookup. When the 4th argument is FALSE, you are telling Excel to find an exact matching value. Note: You may see 0 used instead of FALSE in the 4th argument. Excel evaluates 0 as FALSE, and any non-zero number as TRUE.

Now that we have the overall concept down, let s dig into the Excel details. When we humans perform a range lookup, we love seeing both the start and end points. For example, in the sales bonus illustration above, there are From and To columns. Being able to see both sides of the range makes us feel warm and fuzzy. Content. Comfortable. But, here is the hack: VLOOKUP only needs the From column! The implications of this are important. So, let s unpack them. First, here is an updated table that would work perfectly with VLOOKUP: Here is how I like to think about VLOOKUP. I like to think about it operating in two stages. In stage one, it looks in the first column ONLY. It starts at the top, and goes down one row at a time looking for its matching value. Once it finds it match, then it enters stage two, where it shoots to the right to retrieve the related value. So, when the 4th argument is TRUE (or omitted), it will look down the Sales column until it finds its row. Any sales amount that is >= 0 and < 1,000 will return a

bonus amount of 0. And sales >= 1,000 and < 2,500 will return 50. And so on. following formula in to cell C7 to retrieve the bonus amount from Table1: =VLOOKUP(B7,Table1,2,TRUE) Now that we see how this works, it is easy to understand why the data must be sorted in ascending order when the 4th argument is TRUE. When the sales amount is 12,345, VLOOKUP returns the expected bonus amount of 500, as shown below. In order for VLOOKUP to return an accurate result when doing a range lookup, the table must be sorted in ascending order by the lookup column. Hopefully, this helps clarify the sort order issue, which we discussed at length in the first VLOOKUP hack. Let s explore this capability with a few examples. Example 1: Bonus If we wanted Excel to determine the bonus amount based on sales, we would write the That is the basic operation of range lookups, but, we can apply this in many different ways. For example, we can do a lookup on date values.

Example 2: Fiscal Periods Fiscal periods you mean dates? Yes VLOOKUP can even work with dates! For example, let s say we need to create fiscal periods based on transaction dates. We could set up a fiscal period table (Table3), like this one: The formula written into D15 and then filled down, is: =VLOOKUP(B15,Table3,2,TRUE) Example 3: Single Column Then, it would be easy to have VLOOKUP retrieve the corresponding quarter label for a set of transactions. For example, we could use VLOOKUP to populate column D shown below. We can even do a range lookup on a single-column lookup table. This technique provides an easy way to return the beginning point of a range. For example, if we need to find the pay period begin date, we could

create a table of pay period begin dates, like this: Then, we can use VLOOKUP to return the value from the 1st column of the table (Table4), like this: =VLOOKUP(B18,Table4,1,TRUE) We could write the formula into D18 and fill it down, as shown below: So, that is what it means to perform a range lookup. In the next post, we ll talk more about the implications of the 4th argument, and how we can use it to help us perform list comparisons, aka, reconciliations! Sample Excel File:

VLOOKUP Hack #3: Exact Match For the 3 rd VLOOKUP hack we ll dig even deeper into the 4th argument. We ll see how we can leverage it to help with our reconciliations and other list comparisons. Detailed Steps In a bank rec, one list is the check register, and the other list is the bank statement. Here is a way-simplified check register: Let s pretend for a moment that we need to compare two lists. We d like to find out which items on one list appear on the other list. This type of thing is often referred to as a list comparison. Accountants often refer to this task as a reconciliation. And here is the activity per the bank we downloaded from the bank website: So, let s use VLOOKUP to complete one of the most common reconciliations of all, a bank rec.

Now, we have a simple question. Which checks in the check register have cleared the bank? That is, which checks on the check register are also found in the bank activity table. When a check is found in the bank activity table, we want to return the amount. This sounds like a job for VLOOKUP. So, we write the following formula =VLOOKUP([Ck Num],Table1,2) We get these results: Specifically, we get an amount for every check, even those that haven t cleared the bank! Specifically, checks 1003 and 1005 are not in the bank table, but, the formula retrieves a value for them. So, what are we supposed to do? Do the bank rec manually? No! This brings us to our next hack. Hack In the formula above, the 4th argument is omitted, so, it is performing a range lookup. We discussed this in detail in the previous post. When VLOOKUP performs a range lookup, it is not looking for an exact matching value. Instead, it is looking for a value that falls between a range of values. For example, 1003 returns 110 from the bank activity table because 1003 is >=1002

and <1004. Upon reflection, this is exactly what we would expect after understanding range lookups from the previous post. Now, here s the hack that will help. Now, we can easily see which checks have cleared the bank (those where the amount per bank is returned), and which are still outstanding (#N/A). Hack: when the 4th argument is FALSE, VLOOKUP returns #N/A when no matching value is found! So, let s modify the formula above by using FALSE (or 0) as the 4th argument: =VLOOKUP([Ck Num],Table1,2,FALSE) Yes it worked! The update is shown below. So, we are good, right? Well, not so fast. You see, the #N/A error will trickle down to mess up any formulas that include the range. For example, perhaps we want to compute a total, as shown below.

So, is there a way to clean up the #N/A errors, so that the reconciliation will look cleaner and so that the total formula won t be broken? Yes we can just get a little help from the IFERROR function. Here s what that will look like: In summary, IFERROR will return its first argument, unless it is an error. If so, it will return the second argument instead. So, we can replace the #N/A with something else, for example, we could replace it with 0 like this: =IFERROR(VLOOKUP([Ck Num],Table1,2,FALSE),0) Or, we could replace it with a text string by enclosing the text string in quotes, like this: =IFERROR(VLOOKUP([Ck Num],Table1,2,FALSE),"Outstanding") Now it is very clear which checks are still outstanding, and the total works! VLOOKUP Hack #4: Column Labels Now, we are going to explore a hack for the 3rd argument. Here, we ll hack the 3rd argument so that it references column labels instead of the column position. Check it.

Objective Here s the deal. The 3rd argument of the VLOOKUP function is officially known as col_index_num. This represents the position of the value you want returned. To return the amount from the 2nd column in Table1, we could use the following formula written into C5: =VLOOKUP(B5, Table1, 2, 0) For example, if you want to return the amount from the 2nd position, or column, within the lookup range, you would enter 2 for the argument. Consider the screenshot below. But, what if we wanted to communicate with Excel using the column label (Amount) instead of an integer value (2). For example, we wanted to do something like this: =VLOOKUP(B5, Table1, "Amount", 0) But, when we enter such a formula we get an error. So, apparently Excel does not allow us to reference the column using the column label. Or does it?

Hack Essentially, we would like Excel to translate the column label (Amount) into the corresponding integer (2). Here s how. Hack: use MATCH instead of an integer for the 3rd argument. The MATCH function returns the relative position of a list item. So, we will ask the MATCH function to find the label (Amount) within the table header row, and return the position number. Then, VLOOKUP will use that position number. For example, the following formula would return 2 since Amount is the second column label within the table: =MATCH("Amount", Table1[#Headers], 0) But, since Amount is already entered into cell C4, we can simple reference C4 instead, as follows: =MATCH(C4, Table1[#Headers], 0) This MATCH function would return 2 since the Amount label is in the 2nd table column. So, replacing the 2 in our original formula with the MATCH function would look like this: =VLOOKUP(B5, Table1, MATCH(C4,Table1[#Headers],0), 0) This technique allows us to reference the column labels instead of the position number. But, Jeff, hang on. That seems WAY more complicated than just using an integer. Why would we want to

go through such trouble? Well, let s check out a few fun applications of this technique. Applications Application 1: Column order changes If the column order changes, a traditional VLOOKUP function (written with an integer 3rd argument) will break. Why? Because Excel doesn t update the integer value accordingly. Using MATCH instead prevents this error, making your workbook more reliable and efficient. For example, First name is originally in the 2nd column. But, then we move it to the 3rd column, as illustrated below. Using the MATCH function as the 3rd argument allows the VLOOKUP to continue to retrieve the desired

First name, even as the column order changes. Note: the lookup column must continue to be the first column within the lookup range. For example, we return the State column, as shown below. Application 2: Insert new columns If a new worksheet column is inserted between the lookup column and the return column, a traditional VLOOKUP function will break because Excel won t update the integer value accordingly. But, using MATCH instead of an integer enables the VLOOKUP function to automatically adapt. This reduces the likelihood of an error and improves efficiency since you won t need to rewrite the formula after inserting a new column. Later, we insert a new column Address2. Our hacked VLOOKUP function continues to return the State code without modification, as shown below.

different amounts, depending on the discount level of the customer. Application 3: Two-dimensional lookups When we think about traditional VLOOKUP functions, we think of them as searching for a matching value down, vertically. But, with MATCH, we can perform twodimensional lookups, where VLOOKUP searches down through the rows and MATCH searches across the columns. This opens up some interesting possibilities. For example, let s say we have some inventory items that we sell for We could create a master table of items, and use one column for each pricing level or tier. Then, we could define the tier in an input cell (C7), and have Excel search down the list for the matching item, and then right to find the price based on the specified tier.

And these are just a few ways to apply the MATCH hack to VLOOKUP! If you have any other VLOOKUP hacks, please share by posting a comment below thanks! VLOOKUP Hack #5: Different Tables We are right in the middle of a blog series called. We started by exploring the 4th VLOOKUP argument. Then we hacked the 3rd argument. Objective Before we get too far, let's be clear about the goal. The goal is to write a VLOOKUP function that will retrieve a value from a table that the user specifies. That is, there are a bunch of different lookup tables, and we want VLOOKUP to retrieve a value from whichever table the user identifies. I've created a short video demonstration as well as a written narrative for reference. Now, as you may have imagined, it is time to hack the 2rd argument. In this post, we'll allow the user to retrieve values from different lookup tables. We would like to be able to enter a taxable income amount into a cell, and have Excel compute the correct tax amount. To compute the tax amount, we need to know a few things.

For starters, we need to know the taxable income. So, we create a little input cell (D7) to store the taxable income, as shown below. We'll need to retrieve several values from the table in order to compute the correct tax amount. Let's start by retrieving the marginal tax rate. The tax rate is in the 2nd column within the table (named Single), so, we write the following formula. Then, we need to know the tax rates. We get the tax rates from the IRS and enter them into a table (named Single), as shown below. =VLOOKUP(D7,Single,2,TRUE) When we inspect the formula result in D8, we confirm it returns 25% when taxable income is 50,000, so we are off to a great start, as shown below.

The VLOOKUP function retrieves the rate from the Single table. But, we know that the IRS creates separate tax tables for each filing status. So, we create one table for each filing status, as shown below. These tables are named Single, MFJ, HH, and MFS. Now, we just need to allow the user to identify the correct filing status table. So, we quickly update our workbook, and add an input cell D6 to allow the user to

enter the desired table name, as shown below. So, apparently, VLOOKUP doesn't allow us to identify the table name. Or...does it? That brings us to the hack! Now, we just need to update our formula to refer to the tax table input cell D6 instead of the table name. So, we just update the 2nd argument accordingly: =VLOOKUP(D7,D6,2,TRUE) But, drats! We get an error, as shown below. Hack We can specify the lookup table, but, we need an assist from another function. So, here is the hack. Hack: Use INDIRECT as the 2nd argument The INDIRECT function converts a text value, such as "Single" in D6, into a valid Excel reference. That is, it will convert the text string "Single" into the corresponding table name Single. We update our formula by wrapping the INDIRECT function around the input cell D6 reference, as shown below:

=VLOOKUP(D7,INDIRECT(D6),2,TRUE) And, yes...it works! argument. So, the formula would be something like this: =D7-VLOOKUP(D7,INDIRECT(D6),1,TRUE) The results are shown in D9 below. Now that we've got that part working, we can finish out the tax calculation as follows. The next step is to compute the marginal income that will be taxed at the marginal rate. In theory, this is done by taking the taxable income amount (eg, 50,000) and then subtracting the beginning amount of the corresponding tax bracket (eg, 37,950). Fortunately, we discussed how to retrieve the beginning point of a range in a previous post by using 1 as the 3rd We can then compute the marginal tax by multiplying the marginal income by the marginal rate. And finally, we need to retrieve the amount from the Plus column (so that we can add it to the marginal tax amount) with the following formula:

=VLOOKUP(D7,INDIRECT(D6),3,TRUE) We add the retrieved amount to the marginal tax, and we have the Total Tax amount, as shown below. Of course, we could combine these into a single formula, and, provide an in-cell drop down with data validation for the user to select the table. The sample file includes these enhancements in case you'd like to check them out. Conclusion Hopefully, these items will help you get more mileage out of VLOOKUP. It is an amazing function! With the formulas complete, we are now able to easily enter the taxable income and tax table into the input cells, and Excel computes the corresponding tax. Nice! Also, I have a few more useful tricks, so, please stay tuned for additional VLOOKUP hacks!

Sample Files: Hack 1: https://www.exceluniversity.com/vlookup-hack-1-sort-order/ Hack 2: https://www.exceluniversity.com/vlookup-hack-2-range-lookups/ Hack 3: https://www.exceluniversity.com/vlookup-hack-3-exact-match Hack 4: https://www.exceluniversity.com/vlookup-hack-4-column-labels/ Hack 5: https://www.exceluniversity.com/vlookup-hack-5-different-tables/