Microsoft Excel 2013 Data Analysis and Business Modeling

  

Microsoft Excel 2013: Data Analysis and Business Modeling Wayne L. Winston Published with the authorization of Microsoft Corporation by: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, California 95472 Copyright © 2014 by Wayne L .Winston

All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any

means without the written permission of the publisher.

  ISBN: 978-0-7356-6913-0 2 3 4 5 6 7 8 9 10 LSI 9 8 7 6 5 4 Printed and bound in the United States of America.

Microsoft Press books are available through booksellers and distributors worldwide. If you need support related

to this book, email Microsoft Press Book Support at Please tell us what you think of

this book a

Microsoft and the trademarks listed at

re trademarks of the Microsoft group of companies. All other marks are property of

their respective owners.

  

The example companies, organizations, products, domain names, email addresses, logos, people, places, and

events depicted herein are fictitious. No association with any real company, organization, product, domain name,

email address, logo, person, place, or event is intended or should be inferred.

This book expresses the author’s views and opinions. The information contained in this book is provided without

any express, statutory, or implied warranties. Neither the author, O’Reilly Media, Inc., Microsoft Corporation, nor

its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or

indirectly by this book.

  Acquisitions and Developmental Editor: Kenyon Brown Production Editor: Kara Ebrahim Editorial Production: nSight, Inc. Technical Reviewer: Peter Myers Copyeditor: nSight, Inc. Indexer: nSight, Inc. Cover Design: Twist Creative • Seattle Cover Composition: Ellie Volckhausen Illustrator: Rebecca Demarest

  [2014-01-31]

Contents at a glance

  

  ChAptEr 28

  ChAptEr 27

  ChAptEr 26

  ChAptEr 23 ChAptEr 25

  

ChAptEr 21

ChAptEr 22

  ChAptEr 20

  

ChAptEr 18

ChAptEr 19

  ChAptEr 16 ChAptEr 17

  ChAptEr 15

  

ChAptEr 13

ChAptEr 14

  

  ChAptEr 1

   ChAptEr 11

  

  

  

  

  

  

  

  

   ChAptEr 3

  

  

  ChAptEr 31

ChAptEr 32 Using Solver for capital budgeting 297 ChAptEr 33 Using Solver for financial planning 305 ChAptEr 34 Using Solver to rate sports teams 313 ChAptEr 35 Warehouse location and the GrG Multistart

  

  ChAptEr 36

ChAptEr 37 the traveling salesperson problem 335 ChAptEr 38 Importing data from a text file or document 339 ChAptEr 39 Importing data from the Internet 345 ChAptEr 40 Validating data 349 ChAptEr 41 Summarizing data by using histograms 359 ChAptEr 42 Summarizing data by using descriptive statistics 369 ChAptEr 43 Using pivottables and slicers to describe data 385 ChAptEr 44

  

  ChAptEr 45

  ChAptEr 46

  ChAptEr 47 ChAptEr 55

  ChAptEr 56 ChAptEr 61

  ChAptEr 62 ChAptEr 64

  ChAptEr 65

  ChAptEr 67

  ChAptEr 68

  ChAptEr 69

  ChAptEr 71

  ChAptEr 73

  ChAptEr 77 ChAptEr 78

  ChAptEr 79 ChAptEr 80

  ChAptEr 81 ChAptEr 84

  ChAptEr 85

  ChAptEr 86

  

  

  Chapter 1

  

  

  

  Chapter 2

  

  

  

  Chapter 3

  

  

What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. to participate in a brief online survey, please visit: microsoft.com/learning/booksurvey Contents

  Chapter 4

  

  

  Chapter 5

  

  

  

  

  Chapter 6

  

  

  

Chapter 7

  

  

  Chapter 8

  

  

  

  Chapter 9

  

  Chapter 10

  

  

  Chapter 11

  

  

  Chapter 12

  Chapter 15

  

  Chapter 22

  

  Chapter 27

  Chapter 30

  

Chapter 32 Using Solver for capital budgeting 297 Answer to this chapter’s question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .297 Handling other constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .300 Solving binary and integer programming problems . . . . . . . . . . . .301 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .303 Chapter 33 Using Solver for financial planning 305 Answers to this chapter’s questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .305 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .310 Chapter 34 Using Solver to rate sports teams 313 Answer to this chapter’s question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .314 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .318 Chapter 35 Warehouse location and the GRG Multistart and Evolutionary Solver engines 319

  

  

  Chapter 36

  Chapter 43

  

  Chapter 47

  

  Chapter 49

  Chapter 51

  

  

  

Chapter 58

  

  Chapter 59

  Chapter 65

  

  Chapter 68

  

  

Chapter 72

  

  Chapter 73

  

  

  

  Chapter 77

  Chapter 79

  

  books and learning resources for you. to participate in a brief online survey, please visit: microsoft.com/learning/booksurvey

Introduction

  hether you work for a Fortune 500 corporation, a small company, a government agency, or a not-for-profit organization, if you’re reading this introduction the

  W

  chances are you use Microsoft Excel in your daily work. Your job probably involves sum- marizing, reporting, and analyzing data. It might also involve building analytic mod- els to help your employer increase profits, reduce costs, or manage operations more efficiently.

  Since 1999, I’ve taught thousands of analysts at organizations such as 3M, Booz Allen Hamilton consulting, Bristol-Myers Squibb, Broadcom Cisco Systems, Deloitte Consulting, Drugstore.com, eBay, Eli Lilly, Ford, General Electric, General Motors, Intel, Microsoft, Morgan Stanley, NCR, Owens Corning, Pfizer, Proctor & Gamble, PWC, Sch- lumberger, Tellabs, the U.S. Army, the U.S. Department of Defense, and Verizon how to use Excel more efficiently and productively in their jobs. Students have often told me that the tools and methods I teach in my classes have saved them hours of time each week and provided them with new and improved approaches for analyzing important business problems.

  I’ve used the techniques described in this book in my own consulting practice to solve many business problems. For example, I have used Excel to help the Dallas Mavericks and New York Knickers NBA basketball teams evaluate referees, players, and lineups. During the last 15 years I have also taught Excel business modeling and data analysis classes to MBA students at Indiana University’s Kelley School of Business. (As proof of my teaching excellence, I have won over 45 teaching awards, and have won the school’s overall MBA teaching award six times.) I would like to also note that 95 percent of MBA students at Indiana University take my spreadsheet modeling class even though it is an elective.

  The book you have in your hands is an attempt to make these successful classes available to everyone. Here is why I think the book will help you learn how to use Excel more effectively:

  ■

  The materials have been tested while teaching thousands of analysts working for Fortune 500 corporations and government agencies, including the U.S. Army.

  ■

  I’ve written the book as though I am talking to the reader. I hope this approach transfers the spirit of a successful classroom environment to the written page.

  ■

  I teach by example, which makes concepts easier to master. These examples are constructed to have a real-world feel. Many of the examples are based on ques- tions sent to me by employees of Fortune 500 corporations.

  ■

  For the most part, I lead you through the approaches I take in Excel to set up and answer a wide range of data analysis and business questions. You can follow along with my explanations by referring to the sample worksheets that accom- pany each example. However, I have also included template files for the book’s examples on the companion website. If you want to, you can use these tem- plates to work directly with Excel and complete each example on your own.

  ■

  For the most part, the chapters are short and organized around a single con- cept. You should be able to master the content of most chapters with at most two hours of study. By looking at the questions that begin each chapter, you’ll gain an idea about the types of problems you’ll be able to solve after mastering a chapter’s topics.

  ■

  In addition to learning about Excel formulas, you will learn some important math in a fairly painless fashion. For example, you’ll learn about statistics, forecasting, optimization models, Monte Carlo simulation, inventory modeling, and the mathematics of waiting in line. You will also learn about some recent developments in business thinking, such as real options, customer value, and mathematical pricing models.

  ■

  At the end of each chapter, I’ve provided a group of practice problems (over 600 in total) that you can work through on your own. These problems will help you master the information in each chapter. Answers to all problems are included in files on the book’s companion website. Many of these problems are based on actual problems faced by business analysts at Fortune 500 companies.

  ■

  Most of all, learning should be fun. If you read this book, you will learn how to predict U.S. presidential elections, how to set football point spreads, how to determine the probability of winning at craps, and how to determine the probability of a specific team winning an NCAA tournament. These examples are interesting and fun, and they also teach you a lot about solving business problems with Excel.

  Note To follow along with this book, you must have Excel 2013. Previous ver- sions of this book can be used with Excel 2003, Excel 2007, or Excel 2010.

What’s new in this edition

  This edition of the book contains the following changes:

  ■ An explanation of Excel’s 2013 exciting Flash Fill feature ■ An explanation of how to delete invisible characters which often mess up

  calculations.

  ■ An explanation of the following new Excel 2013 functions: SHEET, SHEETS, FORMULATEXT, and ISFORMULA. ■ A simple method for listing all of a workbook’s worksheet names. ■ A chapter describing the exciting new field of analytics. ■ How to create PivotTables from data in disparate locations or based on another PivotTable. ■

  How to use Excel 2013’s new Timeline feature to filter PivotTables based on dates.

  ■ A description of Excel 2013’s Data Model.

  .

  ■ A description of Excel 2013’s PowerPivot add-in ■ How to use Power View to create mind blowing charts and graphics. ■ A new chapter on charting tricks and a general description of charting in Excel 2013. ■ Over 30 new problems have been added.

What you should know before reading this book

  To follow the examples in this book you do not need to be an Excel guru. Basically, the two key actions you should know how to do are the following:

  ■ Enter a formula You should know that formulas must begin with an equals

  sign (=). You should also know the basic mathematical operators. For example, you should know that an asterisk (*) is used for multiplication, a forward slash (/) is used for division, and the caret key (^) is used to raise a quantity to a power.

  ■ Work with cell references You should know that when you copy a formula

  that contains a cell reference such as $A$4 (an absolute cell reference, which is created by including the dollar signs), the formula still refers to cell A4 in the cells you copy it to. When you copy a formula that contains a cell reference such as $A4 (a mixed cell address), the column remains fixed, but the row changes. Finally, when you copy a formula that contains a cell reference such as A4 (a relative cell reference), both the row and the column of the cells referenced in the formula change.

How to use this book

  As you read along with the examples in this book, you can take one of two approaches:

  ■

  You can open the template file that corresponds to the example you are study- ing and complete each step of the example as you read the book. You will be surprised how easy this process is and amazed with how much you learn and retain. This is the approach I use in my corporate classes.

  ■

  Instead of working in the template, you can follow my explanations as you look at the final version of each sample file.

Using the companion content

  This book features a companion website that makes available to you all the sample files you use in the book’s examples (both the final Excel workbooks and starting templates you can work with on your own). The workbooks and templates are organized in folders named for each chapter. The answers to all chapter-ending problems in the book are also included with the sample files. Each answer file is named so that you can identify it easily. For example, the file containing the answer to Problem 2 in Chapter 10 is named s10_2.xlsx.

  To work through the examples in this book, you need to copy the book’s sample files to your computer. These practice files, and other information, can be downloaded from the book’s detail page, located at:

  

  Display the detail page in your Web browser, and follow the instructions for down- loading the files.

Acknowledgments

  I am eternally grateful to Jennifer Skoog and Norm Tonina, who had faith in me and first hired me to teach Excel classes for Microsoft finance. Jennifer in particular was instrumental in helping design the content and style of the classes on which the book is based. Keith Lange of Eli Lilly, Pat Keating and Doug Hoppe of Cisco Systems, and Den- nis Fuller of the U.S. Army also helped me refine my thoughts on teaching data analysis and modeling with Excel.

  Editors Kenyon Brown and Rachel Roumeliotis did a great job of keeping me (and the book) on schedule. Peter Myers did a great job with the technical editing. Thanks also to Production Editors Kara Ebrahim and Chris Norton for managing the book’s production. I am grateful to my many students at the organizations where I’ve taught and at the Indiana University Kelley School of Business. Many of them have taught me things I did not know about Excel.

  Alex Blanton, formerly of Microsoft Press, championed this project at the start and shared my vision of developing a user-friendly text designed for use by business analysts.

  Finally, my lovely and talented wife, Vivian, and my wonderful children, Jennifer and Gregory, put up with my long weekend hours at the keyboard.

  Support & feedback The following sections provide information on errata, book support, feedback, and contact information.

Errata

We’ve made every effort to ensure the accuracy of this book and its companion con- tent. If you do find an error, please report it on our Microsoft Press site at oreilly.com:

  1. Go to .

  2. In the Search box, enter the book’s ISBN or title.

  3. Select your book from the search results.

  4. On your book’s catalog page, under the cover image, you’ll see a list of links.

  5. Click View/Submit Errata.

  You’ll find additional information and services for your book on its catalog page. If you need additional support, please e-mail Microsoft Press Book Support at

  Please note that product support for Microsoft software is not offered through the addresses above.

We want to hear from you

  At Microsoft Press, your satisfaction is our top priority, and your feedback our most valuable asset. Please tell us what you think of this book at:

  

  The survey is short, and we read every one of your comments and ideas. Thanks in advance for your input!

  Stay in touch Let’s keep the conversation going! We’re on Twitter

C H A P T E R 1 range names Questions answered in this chapter:

  ■

  I want the total sales in Arizona, California, Montana, New York, and New Jersey. Can I use a formula to compute the total sales in a form such as AZ+CA+MT+NY+NJ instead of SUM(A21:A25) and still get the right answer?

  ■

  What does a formula such as Average(A:A) do?

  ■

  What is the difference between a name with workbook scope and one with worksheet scope?

  ■

  I really am getting to like range names. I have started defining range names for many of the workbooks I have developed at the office. However, the range names do not show up in my formulas. How can I make recently created range names show up in previously created formulas?

  ■

  How can I paste a list of all range names (and the cells they represent) into my worksheet?

  ■

  I am computing projected annual revenues as a multiple of last year’s revenue. Is there a way to have the formula look like (1+growth)*last year?

  ■

  For each day of the week, we are given the hourly wage and hours worked. Can we compute total salary for each day with the wages*hours formula? You have probably worked with worksheets that use formulas such as SUM(A5000:A5049). Then you have to find out what’s contained in cells A5000:A5049. If cells A5000:A5049 contain sales in each US state, wouldn’t the formula SUM(USSales) be easier to understand? In this chapter, you learn how to name individual cells or ranges of cells and how to use range names in formulas.

How can I create named ranges?

  There are three ways to create named ranges:

  ■

  By entering a range name in the Name box

  ■

  By clicking Create From Selection in the Defined Names group on the Formulas tab

  ■

  By clicking Name Manager or Define Name in the Defined Names group on the

  Formulas tab

Using the Name box to create a range name

  The Name box (shown in Figure 1-1) is located directly above the label for column A. (To see the Name box, click the Formula bar.) To create a range name in the Name box, simply select the cell or range of cells that you want to name, click in the Name box, and then type the range name you want to use. Press Enter, and you’ve created the range name. Clicking the drop-down arrow in the Name box displays the range names defined in the current workbook. You can display all the range names in a workbook by pressing the F3 key to open the Paste Name dialog box. When you select a range name from the Name box, Microsoft Excel 2013 selects the cells corresponding to that range name.

  This enables you to verify that you’ve chosen the cell or range that you intended to name. Range names are not case sensitive.

  

FIGURE 1-1 You can create a range name by selecting the cell range you want to name and then typing the range

name in the Name box.

  For example, suppose you want to name cell F3 east and cell F4 west. See Figure 1-2 and the Eastwestempt.xlsx file. Select cell F3, type east in the Name box, and then press Enter. Select cell F4, type west in the Name box, and press Enter. If you now reference cell F3 in another cell, you see =east instead of =F3. This means that whenever you see the reference east in a formula, Excel will insert whatever is in cell F3.

  FIGURE 1-2 Name cell F3 east and cell F4 west.

  Suppose you want to assign a rectangular range of cells (such as A1:B4) the name Data. Select the cell range A1:B4, type Data in the Name box, and press Enter. Now a formula such as =AVERAGE(Data) would average the contents of cells A1:B4. See the Data.xlsx file and Figure 1-3.

  Name the A1:B4 range Data.

  FIGURE 1-3

  Sometimes, you want to name a range of cells made up of several noncontiguous rectangular ranges. For example, in Figure 1-4 and the Noncontig.xlsx file, you might want to assign the name

  

Noncontig to the range consisting of cells B3:C4, E6:G7, and B10:C10. To assign this name, select any

  one of the three rectangles making up the range (B3:C4 for now). Hold down the Ctrl key and then select the other two ranges (E6:G7 and B10:C10). Now release the Ctrl key, type the name Noncontig in the Name box, and press Enter. Using Noncontig in any formula will now refer to the contents of cells B3:C4, E6:G7, and B10:C10. For example, entering the formula =AVERAGE(Noncontig) in cell E11 yields 4.75 (because the 12 numbers in your range add up to 57, and 57/12 = 4.75).

  FIGURE 1-4 This is how to name a noncontiguous range of cells.

Creating named ranges by using Create From Selection

  The Statestemp.xlsx worksheet contains sales during March for each of the 50 US states. Figure 1-5 shows a subset of this data. You would like to name each cell in the B6:B55 range with the cor- rect state abbreviation. To do this, select the A6:B55 range and click Create From Selection in the

Defined Names group on the Formulas tab (see Figure 1-6) and then select the Left Column check box, as indicated in Figure 1-7

  

FIGURE 1-5 By naming the cells that contain state sales with state abbreviations, you can use the abbreviation

rather than the cell’s column letter and row number when you refer to the cell.

  FIGURE 1-6 Select Create From Selection.

  FIGURE 1-7 Select the Left Column check box.

  Excel now knows to associate the names in the first column of the selected range with the cells in the second column of the selected range. Thus, B6 is assigned the range name AL, B7 is named AK, and so on. Creating these range names in the Name box would have been incredibly tedious! Click the drop-down arrow in the Name box to verify that these range names have been created.

Creating range names by using Define Name

  If you choose Name Manager on the Formulas tab and select Define Name from the menu shown in Figure 1-6, the New Name dialog box shown in Figure 1-8 opens.

  FIGURE 1-8 This is how the New Name dialog box appears before creating any range names. Suppose you want to assign the name range1 (range names are not case sensitive) to the cell range A2:B7. Type range1 in the Name box and then point to the range or type =A2:B7 in the Refers To area. The New Name dialog box will now look like Figure 1-9. Click OK, and you’re done.

  FIGURE 1-9 The New Name dialog box looks like this after creating a range name.

  If you click the Scope arrow, you can select Workbook or any worksheet in your workbook. This decision is discussed later in this chapter, so for now, just choose the default scope of Workbook. You can also add comments for any of your range names.

Name Manager

  If you now click the Name arrow, the name range1 (and any other ranges you have created) appears in the Name box. In Excel 2013, there is an easy way to edit or delete your range names. Open Name

  Manager by selecting the Formulas tab and then click Name Manager from the menu shown

  in Figure 1-6. You now see a list of all range names. For example, for the States.xlsx file, the Name Manager dialog box will look like Figure 1-10.

  To edit any range name, double-click the range name or select the range name and click Edit; you can then change the name of the range, the cells the range refers to, or the scope of the range. To delete any subset of range names, first select the range names you want to delete. If the range names are listed consecutively, select the first range name in the group you want to delete, hold down the Shift key, and select the last range name in the group. If the range names are not listed consecutively, you can select any range name you want to delete and then hold down the Ctrl key while you select the other range names for deletion. Then press the Delete key to delete the selected range names.

  Now look at some specific examples of how to use range names.

  FIGURE 1-10 This is the Name Manager dialog box for States.xlsx.

  Answers to this chapter’s questions This section provides the answers to the questions that are listed at the beginning of the chapter.

  

I want the total sales in Arizona, California, Montana, New York, and New Jersey. Can I

use a formula to compute the total sales in a form such as AZ+CA+MT+NY+NJ instead of

SUM(A21:A25) and still get the right answer?

  Return to the States.xlsx file, in which you assigned each state’s abbreviation as the range name for the state’s sales. If you want to compute total sales in Alabama, Alaska, Arizona, and Arkansas, clearly you could use the formula SUM(B6:B9). You could also point to cells B6, B7, B8, and B9, and the for- mula would be entered as =AL+AK+AZ+AR. The latter formula is self-describing.

  As another illustration of how to use range names, look at the Historicalinvesttemp.xlsx file, shown in Figure 1-11, which contains annual percentage returns on stocks, T-bills, and bonds. (Some rows are hidden in this figure; the data ends in row 89.)

  FIGURE 1-11 This figure shows historical investment data.

  Select the B8:D89 cell range and then choose Formulas and Create From Selection. For this example, names are created in the top row of the range. The B8:B89 range is named Stocks, the C8:C89 range T.Bills, and the D8:D89 range T.Bonds. Now you no longer need to remember where your data is. For example, in cell B91, after typing =AVERAGE(, you can press F3, and the Paste Name dialog box opens, as shown in Figure 1-12. You can also bring up a list of range names that can be pasted in formulas if you start typing and click Use In Formula on the Formulas tab.

  You can add a range name to a formula by using the Paste Name dialog box.

  FIGURE 1-12

  You can select Stocks in the Paste Name list and click OK. After entering the closing parenthesis, the formula, =AVERAGE(Stocks), computes the average return on stocks (11.28 percent). The beauty of this approach is that even if you don’t remember where the data is, you can work with the stock return data anywhere in the workbook!

  This chapter would be remiss if it did not mention the exciting AutoComplete capabilities of Excel 2013. If you begin typing =Average(T, Excel shows you a list of range names and functions that begin with T, and you can just double-click T.Bills to complete the entry of the range name.

  What does a formula such as Average(A:A) do?

  If you use a column name (in the form of A:A, C:C, and so on) in a formula, Excel treats an entire column as a named range. For example, entering the =AVERAGE(A:A) formula averages all numbers in column A. Using a range name for an entire column is very helpful if you frequently enter new data in a column. For example, if column A contains monthly sales of a product, as new sales data are entered each month, your formula computes an up-to-date monthly sales average. Use caution, however, because if you enter the =AVERAGE(A:A) formula in column A, you will get a circular reference mes- sage because the value of the cell containing the average formula depends on the cell containing the average. You learn how to resolve circular references in Chapter 10, “Circular references.” Similarly, entering the =AVERAGE(1:1) formula averages all numbers in row 1.

  

What is the difference between a name with workbook scope and one with worksheet scope?

The Sheetnames.xlsx file will help you understand the difference between range names that have workbook scope and range names that have worksheet scope. When you create names with the

  Name box, the names default to workbook scope. For example, suppose you use the Name box to assign the name sales to the cell range E4:E6 in Sheet3, and these cells contain the numbers 1, 2, and 4, respectively. If you enter a formula such as =SUM(sales) in any worksheet, you obtain an answer of 7 because the Name box creates names with workbook scope, so anywhere in the workbook you refer to the name sales (which has workbook scope), the name refers to cells E4:E6 of Sheet3. In any worksheet, if you now enter the =SUM(sales) formula, you will obtain 7 because anywhere in the workbook, Excel links sales to cells E4:E6 of Sheet3.

  Now suppose that you type 4, 5, and 6 in cells E4:E6 of Sheet1 and 3, 4, and 5 in cells E4:E6 of Sheet2, and then you open Name Manager, give the name jam to cells E4:E6 of Sheet1, and define the scope of this name as Sheet1. Then you move to Sheet2, open Name Manager, give the name jam to cells E4:E6, and define the scope of this name as Sheet2. The Name Manager dialog box now looks like Figure 1-13.

  FIGURE 1-13 The Name Manager dialog box displays worksheet and workbook names.

  Now, what if you enter the =SUM(jam) formula in each sheet? In Sheet 1, =SUM(jam) will total cells E4:E6 of Sheet1. Because those cells contain 4, 5, and 6, you obtain 15. In Sheet2, =SUM(jam) will total cells E4:E6 of Sheet2, yielding 3 + 4 + 5 = 12. In Sheet3, however, the =SUM(jam) formula will yield a #NAME? error because no range is named jam in Sheet3. If you enter the =SUM(Sheet2!jam) formula anywhere in Sheet3, Excel will recognize the worksheet-level name that represents cell range E4:E6 of Sheet2 and yield a result of 3 + 4 + 5 = 12. Thus, by prefacing a worksheet-level name by its sheet name followed by an exclamation point (!), you can refer to a worksheet-level range in a worksheet other than the sheet in which the range is defined.

  I really am getting to like range names. I have started defining range names for many of the workbooks I have developed at the office. However, the range names do not show up in my formulas. How can I make recently created range names show up in previously created formulas?

  Look at the Applynames.xlsx file and Figure 1-14.

  FIGURE 1-14 This figure shows how to apply range names to formulas.

  The price of a product was entered in cell F3 and product demand of =10000–300*F3 in cell F4. The unit cost and fixed cost are entered in cells F5 and F6, respectively, and profit is computed in cell F7 with the =F4*(F3–F5)–F6 formula. In this example, Formulas, Create From Selection, and then

  Left Column are used to name cell F3 price, cell F4 demand, cell F5 unit cost, cell F6 fixed cost, and cell

  F7 profit. You would like these range names to show up in the cell F4 and cell F7 formulas. To apply the range names, first select the range where you want the range names applied (in this case, F4:F7). Now open the Defined Names group on the Formulas tab, click the Define Name arrow, and then choose Apply Names. Highlight the names you want to apply and then click OK. Note that cell F4 now contains the =10000–300*price formula, and cell F7 contains the =demand*(price–unit_cost)– fixed_cost formula, as you wanted.

  By the way, if you want the range names to apply to the entire worksheet, select the entire work- sheet by clicking the Select All button at the intersection of the column and row headings.

  How can I paste a list of all range names (and the cells they represent) into my worksheet?

  Press F3 to open the Paste Name box and then click the Paste List button. (See Figure 1-12.) A list of range names and the cells each corresponds to will be pasted into your worksheet, beginning at the current cell location.

  

I am computing projected annual revenues as a multiple of last year’s revenue. Is there a way

to have the formula look like (1+growth)*last year?

  The Last year.xlsx file contains the solution to this problem. As shown in Figure 1-15, you want to com- pute revenues for 2012–2018 that grow at 10 percent per year off a base level of $300 million in 2011.

  FIGURE 1-15 Create a range name for the previous year.

  To begin, use the Name box to name cell B3 growth. Now comes the good part! Move the cursor to B7 and open the New Name dialog box by clicking

  Define Name in the Defined Names group on the Formulas tab. Fill in the New Name dialog box as shown in Figure 1-16.

  In any cell, this name refers to the cell above the active cell.

  FIGURE 1-16

  Because you are in cell B7, Excel interprets this range name always to refer to the cell above the current cell. This would not work if, in the B6 cell reference, the 6 were dollar signed because dollar signing the 6 would prevent the row reference from changing to pick up the row directly above the active cell. If you enter the =previous*(1+growth) formula in cell B7 and copy it down to the B8:B13 range, each cell will contain the formula you want and will multiply 1.1 by the contents of the cell directly above the active cell.

  For each day of the week, we are given the hourly wage and hours worked. Can we compute total salary for each day with the wages*hours formula?

  As shown in Figure 1-17 (see the Namedrows.xlsx file), row 12 contains daily wage rates, and row 13 contains hours worked each day.

  FIGURE 1-17 In any cell, this name refers to the cell above the active cell.

  You can select row 12 (by clicking the 12) and use the Name box to enter the name wage. Select row 13 and type the name hours in the Name box. If you now enter the wage*hours formula in cell F14 and copy this formula to the G14:L14 range, you can see that Excel finds the wage and hour val- ues and multiplies them in each column.

  Remarks ■ Excel does not allow you to use the letters r and c as range names.

  ■ The only symbols allowed in range names are periods (.) and underscores (_). ■ If you use Create From Selection to create a range name, and your name contains spaces,

  Excel inserts an underscore (_) to fill in the spaces. For example, Product 1 is created as Product_1.

  ■ Range names cannot begin with numbers or look like a cell reference. For example, 3Q and A4

  are not allowed as range names. Because Excel 2013 has more than 16,000 columns, a range name such as cat1 is not permitted because there is a CAT1 cell. If you try to name a cell CAT1, Excel tells you the name is invalid. Probably your best alternative is to name the cell cat1_.

  Problems 1.

  The Stock.xlsx file contains monthly stock returns for General Motors and Microsoft. Name the ranges containing the monthly returns for each stock and compute the average monthly return on each stock.

  3.

  In cells Q5 and Q6 in the Citydistances.xlsx file, you can enter the latitude and longitude of any city and, in Q7 and Q8, the latitude and longitude of a second city. Cell Q10 computes the distance between the two cities. Define range names for the latitude and longitude of each city and ensure that these names show up in the formula for total distance.

  4. The Sharedata.xlsx file contains the numbers of shares you own of each stock and the price of each stock. Compute the value of the shares of each stock with the shares*price formula.

  5. Create a range name that averages the past five years of sales data. Assume annual sales are listed in a single column. Use data in the Last5.xlsx file.

C H A P T E R 2 Lookup functions Questions answered in this chapter:

  ■

  How can 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?

Syntax of the lookup functions

  Lookup functions enable you to look up values from worksheet ranges. In Microsoft Excel 2013, you can 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, this chapter con- centrates on VLOOKUP functions.

  VLOOKUp syntax The syntax of the VLOOKUP function is as follows. The brackets ([ ]) indicate optional arguments.

  VLOOKUP(lookup value,table range,column index,[range lookup]) ■

  Lookup value is the value you 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 you try to match the lookup value, and any other columns in which you want to look up formula results.

  ■ 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 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 ascending numerical order. If the range lookup argument is True or omitted and an exact match to the lookup value is found in the first column of the table range, Excel bases the lookup on the row of the table in which the exact match is found. If the

  range lookup argument is True or omitted and an exact match does not exist, Excel bases the

  lookup on the largest value in the first column that is less than the lookup value. If the range

  lookup argument is False and an exact match to the lookup value is found in the first column

  of the table range, Excel bases the lookup on the row of the table in which the exact match is found. If no exact match is obtained, Excel returns an #N/A (Not Available) response. Note that a range lookup argument of 1 is equivalent to True, whereas a range lookup argument of 0 is equivalent to False.

  hLOOKUp syntax

  In an HLOOKUP function, Excel tries to locate the lookup value in the first row (not the first column) of the table range. For an HLOOKUP function, use the VLOOKUP syntax and change column to row.

  Now, explore some interesting examples of lookup functions.

Answers to this chapter’s questions This section provides the answers to the questions that are listed at the beginning of the chapter. How can 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 numbers in ascending order. Suppose that the tax rate depends on income, as shown in Table 2-1.

  TABLE 2-1 Tax rate on income 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 Lookup.xlsx file, shown in Figure 2-1.

  FIGURE 2-1

Use a lookup function to compute a tax rate. The numbers in the first column of the table range are sorted in ascending order

  First, the relevant information (tax rates and break points) was entered in cell range D6:E9. The table range is named D6:E9 lookup. It’s recommended always to name the cells you’re using as the table range. If you do so, you need not remember the exact location of the table range, and when you copy any formula involving a lookup function, the lookup range will always be correct. To illus- trate how the lookup function works, some incomes were entered in the D13:D17 range. By copying the VLOOKUP(D13,Lookup,2,True) formula from E13 to E14:E17, the tax rate was computed for the income levels listed in D13:D17. Examine how the lookup function worked in cells E13:E17. Note that because the column index in the formula is 2, the answer always comes from the second column of the table range.

  

■ In D13, the income of –$1,000 yields #N/A because –$1,000 is less than the lowest income

  level in the first column of the table range. If you want a tax rate of 15 percent associated with an income of –$1,000, replace the 0 in D6 with a number that is –1,000 or smaller.

  ■

  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 opposite $10,000, or 30 percent.

  ■

  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, the value of the range lookup argument was changed from True to False, and the

  VLOOKUP(D13,Lookup,2,False) formula was copied from F13 to F14:F17. Cell F14 still yields a 34 percent tax rate because the first column of the table range contains an exact match to $30,000. All the other entries in F13:F17 display #N/A because none of the other incomes in D13:D17 has an exact match in the first column of the table range.

  Given a product ID, how can I look up the product’s price?