You are on page 1of 11

Free Preview – Week #28

Learn Excel from Mr Excel


Copyright 2005 Bill Jelen
All Rights Reserved

Encourage your friends to sign up at


http://www.mrexcel.com/learn-excel.html

Four topics this week about cover using VLOOKUP


to match lists in Excel.
Part 2: CALCULATING with excel 313 of 853

FIND WHICH CUSTOMERS ARE


IN AN EXISTING LIST
Problem: You have a list of month to date sales by customer, as shown
in Fig. 551. Your co-worker sends you a list of sales for yesterday. Figure
out which customers are new so that they can be added to the list.

Part
II

Fig. 551
314 of 853 LEARN EXCEL FROM MR EXCEL

Strategy: Add a column to the new list. In this column, use the MATCH
function. Any customers in the new list without a match in the existing
list will be assigned a value of #N/A. The #N/A values can then be sorted
to the bottom of the list.
The MATCH function requires three arguments. The first argument is
the customer name to be looked up. The second argument is the range
of existing customers. You will want to make the range an absolute ad-
dress, with dollar signs in the reference. This way, the formula can be
easily copied. The third argument is a zero to indicate that you are look-
ing for an exact match.
1) Enter this formula in cell F6 =MATCH(D6,$A$6:$A$25,0). Copy
the formula down to the other cells in your new list, as shown in
Fig. 552.

Fig. 552

The MATCH formula is going to return an integer that represents the


relative row number where the match is found. In the present case, we
don’t really care about the answer, unless a match is not found. If Excel
cannot find a match, the answer will be the #N/A error. The #N/A errors
will always sort to the end of a list.
Part 2: CALCULATING with excel 315 of 853

2) Sort your new list ascending by column F and the new customers
will sort into one spot. You can then copy and paste the new cus-
tomers to the end of your existing list.
Summary: Use the MATCH function to find customers who are not in
an existing list.
Functions Discussed: =MATCH()

USE VLOOKUP TO FIND WHICH CUSTOMERS


ARE IN AN EXISTING LIST
Part
II
Problem: Your co-worker uses VLOOKUP instead of MATCH to find
which values are in an existing list, as shown in Fig. 553. This is differ-
ent from the advice given in the previous chapter. Which is right?

Fig. 553

Strategy: Both are right. In the next chapter, you and your co-worker
will use VLOOKUP to get the new day’s sales for each existing cus-
tomer. Most people seem to master the VLOOKUP function first, so it is
common to see people using the VLOOKUP function to solve this step as
316 of 853 LEARN EXCEL FROM MR EXCEL

well. Both work fine. Again, with VLOOKUP, you are interested in the
#N/A errors. You have to type an additional parameter for VLOOKUP.
The VLOOKUP function requires four arguments. The first argument
is the customer name to be looked up. The second argument is a rect-
angular range with existing customer numbers in the left column of the
range. You will want to make the range an absolute address with dollar
signs in the reference. This way, the formula can be easily copied. The
third argument is the relative column number within the existing range
that you want returned. In this case, you don’t care which column is re-
turned, you are merely looking for the #N/A values. So, you can use “1”.
The fourth argument is a FALSE to indicate that you are looking for an
exact match.
1) The formula for cell F6 is =VLOOKUP(D6,$A$6:$A$25,1,FALSE).
Copy the formula down to the other cells in your new list.
The VLOOKUP formula is going to return the customer name if it
is in the existing list. If Excel cannot find a match, the answer will
be the #N/A error. The #N/A errors will always sort to the end of a
list.
2) Sort your new list ascending by column F and the new customers
will sort into one spot. You can then copy and paste the new cus-
tomers to the end of your existing list.
Summary: You can use a VLOOKUP function to find customers who
are not in an existing list.
Functions Discussed: VLOOKUP

MATCH CUSTOMERS USING VLOOKUP


Problem: You have a list of month-to-date sales by customer. You have
a second list with new sales from today, as shown in Fig. 554. How can
you add the sales from the new list to the old list?
Part 2: CALCULATING with excel 317 of 853

Part
II

Fig. 554

Strategy: Add a new column to the first list. Use the VLOOKUP func-
tion in the new column to grab the sales from the new list.
The VLOOKUP function requires four arguments. The first argument is
the customer name to be looked up. The second argument is a rectangu-
lar range with new customer numbers in the left column of the range. In
the example above, this is F4:G16. You will want to make the range an
absolute address, with dollar signs in the reference: $F$4:$G$16. This
way, the formula can be easily copied. The third argument is the rela-
tive column number within the existing range that you want returned.
Since the sales are in column G, and G is the second column in the range
318 of 853 LEARN EXCEL FROM MR EXCEL

F4:G16, the third argument will be 2. The fourth argument is a FALSE


to indicate that you are looking for an exact match.
The formula for cell C6 is =VLOOKUP(A6,$F$6:$G$16,2,FALSE), as
shown in Fig. 555. Copy the formula down to the other cells in your new
list.

Fig. 555

Look at row 12 in Fig. 556. Since we did not sell anything to this cus-
tomer today, the result is #N/A. While the #N/As were useful in a previ-
ous chapter, they are fairly annoying here. The rule for calculation says
that anything plus #N/A will return #N/A. When you add a new column
to total column B & C, the #N/As will cause problems.
Part 2: CALCULATING with excel 319 of 853

Part
II

Fig. 556

There are several methods for dealing with the #N/A cells. If you can
sort your original list, simply sort by column C. All of the #N/A cells will
sort to the bottom. Use the formula in column D only for the customers
with sales today. In Fig. 557, you would copy D6:D16 and Paste Special
Values into range C6.

Fig. 557
320 of 853 LEARN EXCEL FROM MR EXCEL

Additional Details: You could also use the ISNA function to deal with
VLOOKUP results that return #N/A. The ISNA function will return a
TRUE if the result of a formula is #N/A. You can then use the ISNA
function as the first part of an IF function. One solution is to use ISNA
and IF in the calculation of the new total. As shown in Fig. 558, the new
total is the previous MTD number in B6 plus C6 if it is not #N/A.

Fig. 558

The other solution is to use the ISNA function in the original VLOOKUP
formula. This is the solution that I use most, even though it requires
Excel to calculate the VLOOKUP twice. The formula becomes long:
=IF(ISNA(VLOOKUP(A6,$F$6:$G$16,2,FALSE)),0,VLOOKUP(A6,$F$
6:$G$16,2,FALSE))
Summary: You can use a VLOOKUP function to match customers in
two lists.
Functions Discussed: =VLOOKUP(); =ISNA(); =IF()

WATCH FOR DUPLICATES


WHEN USING VLOOKUP
Problem: In previous chapters, you’ve used the VLOOKUP function to
get sales from a second list into an original list. You need to be aware of
how VLOOKUP handles duplicates in the lookup list.
Here is a scenario where duplicates can cause a problem. You receive
the next day’s sales in a file. When you add the MATCH function to find
Part 2: CALCULATING with excel 321 of 853

new customers, there is one new customer: Sun Life Finc’l, as shown in
Fig. 559.

Part
II

Fig. 559

You realize that this is not really a new customer at all. Someone in the
order entry department created a new customer instead of using the ex-
isting customer named “Sun Life Financial”. As a quick fix, you copy cell
F9 and paste it in cell F6. This seems like a fine solution and resolves
the #N/A error in H6.
However, this will cause problems down the line. When you enter the
VLOOKUP formula in column C to get the current day’s sales, there are
two rows that match Sun Life Financial. The VLOOKUP function is not
capable of handling this. When two rows match a VLOOKUP, the func-
tion will return the sales from the first row in the list. As shown in Fig.
560, in cell C8, the $1295 in sales is coming from cell G6 only instead of
cells G6 and G8.

Fig. 560
322 of 853 LEARN EXCEL FROM MR EXCEL

If you are not absolutely sure that the customers in the lookup table
are unique, you should not use VLOOKUP. Instead, you would use a
SUMIF formula, as shown in Fig. 561. Functions such as COUNTIF and
SUMIF are explained in the next five topics.

Fig. 561

Summary: The VLOOKUP function is excellent, but you need to be


aware of the unintended problems that could be caused by having dupli-
cates in the list.
Functions Discussed: =VLOOKUP(); =SUMIF()

You might also like