The Microsoft Excel MATCH function searches for a value in an array and returns the relative position of that item.
The MATCH function is a built-in function in Excel that is categorized as a Lookup/Reference Function. It can be used as a worksheet function (WS) in Excel. As a worksheet function, the MATCH function can be entered as part of a formula in a cell of a worksheet.
2. Questions answered in this chapter:
• Given monthly sales for several products [Productlookup.xlsx], how
can I write a formula that returns the sales of a product during a
specific month? For example, how much of Product 2 did I sell
during June?
• Given a list of baseball players’ salaries [Baseball.xlsx], how can I
write a formula that yields the player with the highest salary? How
about the player with the fifth-highest salary?
• Given the annual cash flows [Payback.xlsx] from an investment
project, how do I write a formula that returns the number of years
required to pay back the project’s initial investment cost?
3. Suppose you have a worksheet with 5,000 rows containing 5,000
names. You need to find the name John Doe, which you know
appears somewhere (and only once) in the list. Wouldn’t you
like to know of a formula that would return the row number that
contains that name? The MATCH function enables you to find
the first occurrence of a match to a given text string or number
within a given array. You should use the MATCH function
instead of a lookup function when you want the position of a
number in a range rather than the value in a particular cell.
4. The syntax of the match function is:
Match(lookup value, lookup range,[match type])
5. In the explanation that follows, assume that all cells in the
lookup range are in the same column.
In this syntax:
• Lookup value is the value you’re trying to match in the lookup
range.
• Lookup range is the range you’re examining for a match to the
lookup value. The lookup range must be a row or column.
6. Match type=1 requires the lookup range to
consist of numbers listed in ascending
order.
The MATCH function then returns the row
location in the lookup range (relative to the
top of the lookup range) that contains the
largest value in the range that is less than
or equal to the lookup value.
7. Match type=–1 requires the lookup range to
consist of numbers listed in descending order.
The MATCH function returns the row location
in the lookup range (relative to the top of the
lookup range) that contains the last value in the
range that is greater than or equal to the lookup
value.
8. • Match type=0 returns the row location in the lookup
range that contains the first exact match to the lookup
value. When no exact match exists and match type=0,
Excel returns the error message #N/A.
• Most MATCH function applications use match
type=0, but if match type is not included, match
type=1 is assumed. Thus, use match type=0 when the
cell contents of the lookup range are unsorted. This is
the situation you usually face.
9. The Matchex.xlsx file, shown in Figure 4-1, contains three
examples of the MATCH function’s syntax.
10. • In cell B13, the MATCH(“Boston”,B4:B11,0) formula returns
1 because the first row in the B4:B11 range contains the value
Boston. Text values must be enclosed in quotation marks (“”).
In cell B14, the MATCH(“Phoenix”,B4:B11,0) formula returns
7 because cell B10 (the seventh cell in B4:B11) is the first cell
in the range that matches Phoenix. In cell E12, the
MATCH(0,E4:E11,1) formula returns 4 because the last
number that is less than or equal to 0 in the E4:E11 range is in
cell E7 (the fourth cell in the lookup range). In cell G12, the
MATCH(–4,G4:G11,–1) formula returns 7 because the last
number that is greater than or equal to –4 in the G4:G11 range
is contained in cell G10 (the seventh cell in the lookup range).
11. • The MATCH function can also work with an
inexact match. For example, the
MATCH(“Pho*”,B4:B11,0) formula returns
7. The asterisk is treated as a wildcard, which
means that Microsoft Excel searches for the
first text string in the B4:B11 range that begins
with Pho. Incidentally, this same technique can
be used with a lookup function.
12. • If the lookup range is contained in a single row,
Excel returns the relative position of the first
match in the lookup range, moving from left to
right. As shown in the following examples, the
MATCH function is often very useful when it
is combined with other Excel functions such as
VLOOKUP, INDEX, or MAX.
13. You should solve this
1. Using the distances between US cities given in the
Index.xlsx file, write a formula using the MATCH function
to determine (based on the names of the cities) the distance
between any two of the cities.
2. The Matchtype1.xlsx file lists the dollar amounts of 30
transactions in chronological order. Write a formula that
yields the first transaction for which total volume to date
exceeds P10,000.
14. You should solve this
3. The Matchthemax.xlsx file gives the product ID codes
and unit sales for 265 products. Use the MATCH function
in a formula that yields the product ID code of the product
with the largest unit sales.
4. The Buslist.xlsx file gives the amount of time between
bus arrivals (in minutes) at 45th Street and Park Avenue in
New York City. Write a formula that, for any arrival time
after the first bus, gives the amount of time you have to
wait for a bus. For example, if you arrive 12.4 minutes
from now, and buses arrive 5 minutes and 21 minutes from
now, you wait 21 – 12.4 = 8.6 minutes for a bus.