Excel does not allow you to use the
If you use Create from Selection to create a range name, and your
Range names cannot begin with
The only symbols allowed in range names are periods (.) and underscores (_).
The file Stock.xlsx contains monthly stock returns for General Motors and Microsoft.
Open a worksheet and name the range containing the
Given the latitude and longitude of any two cities, the file Citydistances.xlsx computes the distance between any two cities. Define range names for the latitude and longitude of each city and ensure that these
How do I write a formula to compute tax rates based on income?
Given a product ID, how can I look up the product’s price?
Suppose that a product’s price changes over time. I know the date the product was sold. How can I write a formula to compute the product’s price?
Lookup functions enable you to “look up” values from worksheet ranges. Microsoft Office Excel allows you to perform both vertical lookups (by using the VLOOKUP function) and horizontal lookups (by using the HLOOKUP function). In a vertical lookup, the lookup operation starts in the first column of a worksheet range. In a horizontal lookup, the operation starts in the first row of a worksheet range. Because the majority of formulas using lookup functions involve vertical lookups, we’ll concentrate on VLOOKUP functions.
The syntax of the VLOOKUP function is as
VLOOKUP(lookup value,table range,column index,[range lookup])
Lookup value is the value that we want to look up in the first column of the table range.
Table range
is the range that contains the entire lookup table. The table range includes the first column, in which we try and match the lookup value, and any other
Column index is the column number in the table range from which the value of the lookup function is obtained.
Range lookup
is an optional argument. The point of range lookup is to allow you to specify an exact or approximate match. If the range lookup argument is
True
or omitted, the first column of the table range must be in
In an HLOOKUP function, Excel
Let’s explore some interesting examples of lookup functions.
How do I write a formula to compute tax rates based on income?
The following example shows how a VLOOKUP function works when the first column of the table range consists of
|
Income level |
Tax rate |
|---|---|
|
$0–$9,999 |
15% |
|
$10,000–$29,999 |
30% |
|
$30,000–$99,999 |
34% |
|
$100,000 and over |
40% |
To see an example of how to write a formula that computes the tax rate for any income level, open the file Lookup.xlsx, shown in Figure 2-1.
Figure 2-1:
Using a lookup function to compute a tax rate. The numbers in the first column of the table range are sorted in ascending order.
I
In D13, the income of –$1,000 yields #N/A because –$1,000 is less than the
In D14, the income of $30,000 exactly matches a value in the first column of the table range, so the function returns a tax rate of 34 percent.
In D15, the income level of $29,000 does not exactly match a value in the first column of the table range, which means the lookup function stops at the largest number less than $29,000 in the first column of the range–$10,000 in this case. This function returns the tax rate in column 2 of the table range
In D16, the income level of $98,000 does not yield an exact match in the first column of the table range. The lookup function stops at the largest number less than $98,000 in the first column of the table range. This returns the tax rate in column 2 of the table range opposite $30,000–34 percent.
In D17, the income level of $104,000 does not yield an exact match in the first column of the table range. The lookup function stops at the largest number less than $104,000 in the first column of the table range, which returns the tax rate in column 2 of the table range opposite $100,000–40 percent.
In F13:F17, we changed the value of the
range lookup
argument from
True
to
False
and
Given a product ID, how can I look up the product’s price?
Often, the first column of a table range does not consist of numbers in ascending order. For example, the first column of the table range might list product ID codes or employee
Here’s an example. In the file Lookup.xlsx (see Figure 2-2), you can see the prices for five products, listed by their ID code. How do you write a formula that will take a product ID code and return the product price?
Figure 2-2:
Looking up prices from product ID codes. When the table range isn’t sorted in ascending order, enter False as the last argument in the lookup function formula.
Many people would enter the formula as I have in cell I18: VLOOKUP(H18,Lookup2,2) . However, note that when you omit the fourth argument (the range lookup argument), the value is assumed to be True . Because the product IDs in the table range Lookup2 (H11:I15) are not listed in alphabetical order, an incorrect price ($3.50) is returned. If we enter the formula VLOOKUP(H18,Lookup2,2,False) in cell I18 , the correct price ($5.20) is returned.
You would also use False in a formula designed to find an employee’s salary using the employee’s last name or ID number.
By the way, you can see in Figure 2-2 that we hid columns A-G. To hide columns in Excel 2007, you begin by selecting the columns you want to hide. Click the Home tab on the Ribbon. In the Cells
Suppose that a product’s price changes over time. I know the date the product was sold. How can I write a formula to compute the product’s price?
Suppose the price of a product depends on the date the product was sold. How can you use a lookup function in a formula that will pick up the correct product price? More
Open table as spreadsheet
|
Date sold |
Price |
|---|---|
|
January-April 2005 |
$98 |
|
May-August 2005 |
$105 |
|
September-December 2005 |
$112 |
We’ll write a formula to determine the correct product price for any date on which the product is sold in the year 2005. For variety, we’ll use an HLOOKUP function. I’ve placed the dates when the price changes in the first row of the table range. See the file Datelookup.xlsx, shown in Figure 2-3.
Figure 2-3:
Using an HLOOKUP function to determine a price that changes depending on the date it’s sold.
I copied from C8 to C9:C11 the formula HLOOKUP(B8,lookup,2,TRUE) . This formula tries to match the dates in column B with the first row of the range B2:D3. At any date between 1/1/05 and 4/30/05, the lookup function will stop at 1/1/05 and return the price in B3; for any date between 5/01/05 and 7/31/05, the lookup stops at 5/1/05 and returns the price in C3; and for any date later than 8/01/05, the lookup stops at 8/01/05 and returns the price in D3.

Head First Data Analysis: A Learner's Guide to Big Numbers, Statistics, and Good Decisions

Microsoft Excel 2010: Data Analysis and Business Modeling

Pivot Table Data Crunching for Microsoft Office Excel 2007

Learn Excel 2007 Essential Skills with The Smart Method: Courseware tutorial for self-instruction to beginner and intermediate level