Tải bản đầy đủ (.pdf) (868 trang)

CÔNG THỨC EXCEL 2003

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (11.47 MB, 868 trang )

John Walkenbach
F
ORMULAS
E
XCEL
2003
“Mr. Spreadsheet,” author of Excel Charts
Includes Power Utility Pak
trial and over 90 sample
workbooks on CD-ROM
Microsoft
®
Office
E 2003

Excel 2003 Formulas

Excel 2003
Formulas
John Walkenbach
Excel 2003 Formulas
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2004 by Wiley Publishing, Inc., Indianapolis, Indiana
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 0-7645-4073-4
Manufactured in the United States of America


10 9 8 7 6 5 4 3 2 1
1B/QS/RQ/QT/IN
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under
Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of
the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance
Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher
for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd.,
Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, E-Mail:
is a trademark of Wiley Publishing, Inc.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: WHILE THE PUBLISHER AND AUTHOR HAVE USED
THEIR BEST EFFORTS IN PREPARING THIS BOOK, THEY MAKE NO REPRESENTATIONS OR WARRANTIES
WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND
SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES
OR WRITTEN SALES MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE
SUITABLE FOR YOUR SITUATION. YOU SHOULD CONSULT WITH A PROFESSIONAL WHERE APPRO-
PRIATE. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY
OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL,
CONSEQUENTIAL, OR OTHER DAMAGES.
For general information on our other products and services or to obtain technical support, please contact our
Customer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317)
572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not
be available in electronic books.
Library of Congress Cataloging-in-Publication Data
Trademarks: Wiley and related trade dress are registered trademarks of Wiley Publishing, Inc., in the United
States and other countries, and may not be used without written permission. [Insert any third-party
trademarks.] All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not
associated with any product or vendor mentioned in this book.

About the Author
John Walkenbach is a leading authority on spreadsheet software, and principal of
JWalk and Associates Inc., a Southern California–based consulting firm that spe-
cializes in spreadsheet application development. John is the author of about 30
spreadsheet books, and has written more than 300 articles and reviews for a variety
of publications, including PC World, InfoWorld, PC Magazine, Windows, and
PC/Computing. He also maintains a popular Internet Web site (The Spreadsheet
Page, www.j-walk.com/ss), and is the developer of the Power Utility Pak, an
award-winning add-in for Microsoft Excel. John graduated from the University of
Missouri, and earned a Masters and PhD from the University of Montana.
Credits
ACQUISITIONS EDITOR
Greg Croy
PROJECT EDITOR
Paul Levesque
TECHNICAL EDITOR
Doug Sahlin
COPY EDITOR
Jean Rogers
EDITORIAL MANAGER
Kevin Kirschner
VICE PRESIDENT & EXECUTIVE
GROUP PUBLISHER
Richard Swadley
VICE PRESIDENT AND
EXECUTIVE PUBLISHER
Bob Ipsen
VICE PRESIDENT AND PUBLISHER
Joseph B. Wikert
EXECUTIVE EDITORIAL DIRECTOR

Mary Bednarek
PROJECT COORDINATOR
Ryan Steffen
GRAPHICS AND PRODUCTION
SPECIALISTS
Beth Brooks
Carrie Foster
Lauren Goddard
Joyce Haughey
Michael Kruzil
Kristin McMullan
Erin Zeltner
QUALITY CONTROL TECHNICIANS
John Greenough
Susan Moritz
Carl Pierce
PERMISSIONS EDITOR
Carmen Krikorian
MEDIA DEVELOPMENT SPECIALIST
Travis Silvers
PROOFREADING AND INDEXING
TECHBOOKS Production Services
Preface
Thanks for buying my book. If you’re interested in developing killer formulas and
taking Excel to a new level, this book is as good as it gets. I’m confident that you’ll
agree that your money was invested wisely.
Why I Wrote This Book
I approached this project with one goal in mind: To write the ultimate Excel book
that would appeal to a broad base of users. That’s a fairly ambitious goal. But based
on the feedback I received from the first two editions, I think I’ve accomplished it.

I’ve been using Excel for nearly a decade, and I also spend a lot of time partici-
pating in the Excel newsgroups on the Internet. As a result, I’m very familiar with
the types of questions that come up time and time again. Much of the material in
this book was inspired by questions on the Excel newsgroups. This book provides
the answers to those questions — along with answers to questions that probably
never occurred to you!
As you probably know, most bookstores offer dozens of Excel books. The vast
majority of these books are general-purpose user guides that explain how to use the
features available in Excel (often by simply rewording the text in the help files). A
few others focus on advanced issues such as macro programming or scientific
applications. None (that’s right, none!) hones in on the one fundamental compo-
nent of Excel that is critically important to every user: formulas. Fact is, formulas
are what make a spreadsheet a spreadsheet. The more you know about formulas, the
better your spreadsheets will be. It’s that simple.
Excel is the spreadsheet market leader, by a long shot. This is the case not only
because of Microsoft’s enormous marketing clout, but because it is truly the best
spreadsheet available. One area in which Excel’s superiority is most apparent is for-
mulas. Excel has some special tricks up its sleeve in the formulas department. As
you’ll see, Excel lets you do things with formulas that are impossible with other
spreadsheets.
It’s a safe bet that only about ten percent of Excel users really understand how
to get the most out of worksheet formulas. In this book, I attempt to nudge you into
that elite group. Are you up to it?
What You Should Know
This is not a book for beginning Excel users. If you have absolutely no experience
with Excel, this may not be the best book for you — unless you’re one of a rare
breed who can learn a new software product almost instantaneously.
vii
To get the most out of this book, you should have some background using Excel.
Specifically, I assume that you know how to


Create workbooks, insert sheets, save files, and other basic tasks

Navigate through a workbook

Use Excel’s menus, toolbars, and dialog boxes

Use basic Windows features, such as file management and copy and paste
techniques
If you’re an experienced spreadsheet user,but you are new to Excel,
Chapter 1 presents a concise overview of what this product has to offer.
What You Should Have
To make the best use of this book, you need a copy of Microsoft Excel. When I
wrote the current edition of the book, I was using Excel 2003 (which is part of
Microsoft Office 2003). With a few exceptions (noted in the text), the material in
this book also applies to all earlier versions of Excel that are still in use.
To use the examples on the companion CD-ROM, you’ll need a CD-ROM drive.
The examples on the CD-ROM are discussed further in the “About the Companion
CD-ROM” section, later in this preface.
I use Excel for Windows exclusively,and I do not own a Macintosh.Therefore,
I can’t guarantee that all of the examples will work with Excel for Macintosh.
Excel’s cross-platform compatibility is pretty good, but it’s definitely not
perfect.
As far as hardware goes, the faster the better. And, of course, the more memory
in your system, the happier you’ll be. And, I strongly recommend using a high-
resolution video mode: at least 1024 x 768.
Conventions in This Book
Take a minute to skim this section and learn some of the typographic conventions
used throughout this book.
viii Preface

Preface ix
Keyboard Conventions
You need to use the keyboard to enter formulas. In addition, you can work with
menus and dialog boxes directly from the keyboard — a method you may find eas-
ier if your hands are already positioned over the keys.
FORMULA LISTINGS
Formulas usually appear on a separate line in monospace font. For example, I may
list the following formula:
=VLOOKUP(StockNumber,PriceList,2,False)
Excel supports a special type of formula known as an array formula. When you
enter an array formula, press Ctrl+Shift+Enter (not just Enter). Excel encloses an
array formula in brackets in order to remind you that it’s an array formula. When I
list an array formula, I include the brackets to make it clear that it is, in fact, an
array formula. For example:
{=SUM(LEN(A1:A10))}
Do not type the brackets for an array formula. Excel will put them in
automatically.
VBA CODE LISTINGS
This book also contains examples of VBA code. Each listing appears in a mono-
space font; each line of code occupies a separate line. To make the code easier to
read, I usually use one or more tabs to create indentations. Indentation is optional,
but it does help to delineate statements that go together.
If a line of code doesn’t fit on a single line in this book, I use the standard VBA
line continuation sequence: a space followed by an underscore character. This indi-
cates that the line of code extends to the next line. For example, the following two
lines comprise a single VBA statement:
If Right(cell.Value, 1) = “!” Then cell.Value _
= Left(cell.Value, Len(cell.Value) - 1)
You can enter this code either exactly as shown on two lines, or on a single line
without the trailing underscore character.

KEY NAMES
Names of keys on the keyboard appear in normal type, for example Alt, Home,
PgDn, and Ctrl. When you should press two keys simultaneously, the keys are con-
nected with a plus sign: “Press Ctrl+G to display the Go To dialog box.”
FUNCTIONS, PROCEDURES, AND NAMED RANGES
Excel’s worksheet functions appear in all uppercase, like so: “Use the SUM function
to add the values in column A.”
Macro and procedure names appear in normal type: “Execute the InsertTotals
procedure.” I often use mixed upper- and lowercase to make these names easier to
read. Named ranges appear in italic: “Select the InputArea range.”
Unless you’re dealing with text inside of quotation marks, Excel is not sensitive
to case. In other words, both of the following formulas produce the same result:
=SUM(A1:A50)
=sum(a1:a50)
Excel, however, will convert the characters in the second formula to uppercase.
Mouse Conventions
The mouse terminology in this book is all standard fare: “pointing,” “clicking,”
“right-clicking,” “dragging,” and so on. You know the drill.
What the Icons Mean
Throughout the book, icons appear to call your attention to points that are particu-
larly important.
This icon indicates a feature new to Excel 2003.
I use Note icons to tell you that something is important — perhaps a con-
cept that may help you master the task at hand or something fundamental
for understanding subsequent material.
x Preface
Tip icons indicate a more efficient way of doing something, or a technique
that may not be obvious.These will often impress your officemates.
These icons indicate that an example file is on the companion CD-ROM.
(See the upcoming “About the Companion CD-ROM”section.)

I use Caution icons when the operation that I’m describing can cause prob-
lems if you’re not careful.
I use the Cross Reference icon to refer you to other chapters that have more
to say on a particular topic.
How This Book Is Organized
There are hundreds of ways to organize this material, but I settled on a scheme that
divides the book into six main parts. In addition, I’ve included a few appendixes that
provide supplemental information that you may find helpful.
Part I: Basic Information
This part is introductory in nature, and consists of Chapters 1 through 3. Chapter 1
sets the stage with a quick and dirty overview of Excel. This chapter is designed for
readers who are new to Excel, but who have used other spreadsheet products. In
Chapter 2, I cover the basics of formulas. This chapter is absolutely essential read-
ing in order to get the most out of this book. Chapter 3 deals with names. If you
thought names were just for cells and ranges, you’ll see that you’re missing out on
quite a bit.
Preface xi
Part II: Using Functions in Your Formulas
This part consists of Chapters 4 through 10. Chapter 4 covers the basics of using
worksheet functions in your formulas. I get more specific in subsequent chapters.
Chapter 5 deals with manipulating text, Chapter 6 covers dates and times, and
Chapter 7 explores various counting techniques. In Chapter 8, I discuss various types
of lookup formulas. Chapter 9 deals with databases and lists, and Chapter 10 covers
a variety of miscellaneous calculations such as unit conversions and rounding.
Part III: Financial Formulas
Part III consists of three chapters (Chapters 11 through 13) that deal with creating
financial formulas. You’ll find lots of useful formulas that you can adapt to your
needs.
Most of the material in Chapters 11 through 13 was contributed by Norman
Harker. Norman is a Senior Lecturer in Real Estate at the University of

Western Sydney (Australia).
Part IV: Array Formulas
This part consists of Chapters 14 and 15. The majority of Excel users know little or
nothing about array formulas — a topic that happens to be dear to me. Therefore I
devote an entire part to this little-used yet extremely powerful feature.
Part V: Miscellaneous Formula Techniques
This part consists of Chapters 16 through 21. They cover a variety of topics — some
of which, on the surface, may appear to have nothing to do with formulas. Chapter
16 demonstrates that a circular reference can be a good thing. In Chapter 17, you’ll
see why formulas can be important when you work with charts, and Chapter 18
covers formulas as they relate to pivot tables. Chapter 19 contains some very inter-
esting (and useful) formulas that you can use in conjunction with Excel’s condi-
tional formatting and data validation features. Chapter 20 covers a topic that I call
“megaformulas.” A megaformula is a huge formula that takes the place of several
intermediary formulas. And what do you do when your formulas don’t work cor-
rectly? Consult Chapter 21 for some debugging techniques.
Part VI: Developing Custom Worksheet Functions
This part consists of Chapters 22 through 25. This is the part that explores Visual
Basic for Applications (VBA), the key to creating custom worksheet functions.
xii Preface
Chapter 22 introduces VBA and the VB Editor, and Chapter 23 provides some nec-
essary background on custom worksheet functions. Chapter 24 covers program-
ming concepts, and Chapter 25 provides a slew of worksheet function examples
that you can use as-is, or customize for your own needs.
Appendixes
What’s a computer book without appendixes? This book has five appendixes. In the
appendixes, you’ll find secrets about importing 1-2-3 files, a quick reference guide
to Excel’s worksheet functions, tips on using custom number formats, and a handy
guide to Excel resources on the Internet. The final appendix describes all the files
on the CD-ROM.

How to Use This Book
You can use this book any way you please. If you choose to read it cover to cover
while lounging on a sunny beach in Maui, that’s fine with me. More likely, you’ll
want to keep it within arm’s reach while you toil away in your dimly-lit cubicle.
Due to the nature of the subject matter, the chapter order is often immaterial.
Most readers will probably skip around, picking up useful tidbits here and there.
The material contains many examples, designed to help you identify a relevant for-
mula quickly. If you’re faced with a challenging task, you may want to check the
index first to see whether the book specifically addresses your problem.
About the Companion CD-ROM
The inside back cover of this book contains a CD-ROM that contains example
workbooks that demonstrate concepts presented in the text. In addition, the
CD-ROM has a trial copy of my Power Utility Pak v5 add-in.
The example workbook files on the companion CD-ROM are not compressed, so
you can access them directly from the CD (installation not required). Power Utility
Pak, however, does require installation. Refer to Appendix E for details.
All CD-ROM files are read-only.Therefore,if you open a file from the CD-ROM
and make any changes to it, you’ll need to save it to your hard drive.
Preface xiii
About the Power Utility Pak Offer
Toward the back of the book, you’ll find a coupon that you can redeem for a dis-
counted copy of my award-winning Power Utility Pak — a collection of useful Excel
utilities, plus many new worksheet functions. I developed this package using VBA
exclusively.
You can also use this coupon to purchase the complete VBA source code for a
nominal fee. Studying the code is an excellent way to pick up some useful pro-
gramming techniques. You can take the product for a test drive by installing the
shareware version from the companion CD-ROM.
Power Utility Pak requires Excel 2000 for Windows or later.
You can always download the most current version of the Power Utility Pak from

my Web site:
www.j-walk.com/ss
Reach Out
I’m always interested in getting feedback on my books. The best way to provide this
feedback is via email. Send your comments and suggestions to:

Unfortunately, I’m not able to reply to specific questions. Posting your question
to one of the Excel newsgroups is, by far, the best way to get such assistance. See
Appendix D for specifics.
Also, when you’re out surfing the Web, don’t overlook my Web site (“The
Spreadsheet Page”):
www.j-walk.com/ss/
Now, without further ado, it’s time to turn the page and expand your horizons.
xiv Preface
Acknowledgments
Thanks to everyone who purchased previous editions of this book. I’m especially
grateful to those who took the time to provide me with valuable feedback and sug-
gestions. I’ve incorporated many of the reader suggestions into this new edition.
I am also grateful to Norman Harker, Senior Lecturer in Real Estate at the
University of Western Sydney (Australia). Norman provided the bulk of the con-
tents of Chapters 11–13.
I would also like to thank Doug Sahlin for his superb technical editing skills.
Doug pointed out several errors and made numerous suggestions to help make this
a better book.
Finally, I wish to thank the folks at Wiley for publishing this book. It is certainly
not your “typical” Excel book, and publishing it was a risky venture. The risk paid
off, however, as evidenced by the fact that it is now in its third edition. Special
thanks to Paul Levesque, my project editor. He made my job much easier.
xv
Contents at a Glance

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . xv
Part I Basic Information
Chapter 1 Excel in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2 Basic Facts about Formulas . . . . . . . . . . . . . . . . . . 29
Chapter 3 Working with Names . . . . . . . . . . . . . . . . . . . . . . 55
Part II Using Functions in Your Formulas
Chapter 4 Introducing Worksheet Functions . . . . . . . . . . . . . 95
Chapter 5 Manipulating Text . . . . . . . . . . . . . . . . . . . . . . . . 111
Chapter 6 Working with Dates and Times . . . . . . . . . . . . . . 135
Chapter 7 Counting and Summing Techniques . . . . . . . . . . . 175
Chapter 8 Using Lookup Functions . . . . . . . . . . . . . . . . . . . 207
Chapter 9 Databases and Lists . . . . . . . . . . . . . . . . . . . . . . . 233
Chapter 10 Miscellaneous Calculations . . . . . . . . . . . . . . . . . 267
Part III Financial Formulas
Chapter 11 Introducing Financial Formulas . . . . . . . . . . . . . . 293
Chapter 12 Discounting and Depreciation Financial
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Chapter 13 Advanced Uses of Financial Functions
and Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Part IV Array Formulas
Chapter 14 Introducing Arrays . . . . . . . . . . . . . . . . . . . . . . . 383
Chapter 15 Performing Magic with Array Formulas . . . . . . . . 405
Part V Miscellaneous Formula Techniques
Chapter 16 Intentional Circular References . . . . . . . . . . . . . . 433
Chapter 17 Charting Techniques . . . . . . . . . . . . . . . . . . . . . . 449
Chapter 18 Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
xvi
Chapter 19 Conditional Formatting and Data Validation . . . . 521
Chapter 20 Creating Megaformulas . . . . . . . . . . . . . . . . . . . . 551

Chapter 21 Tools and Methods for Debugging Formulas . . . . . 569
Part VI Developing Custom Worksheet Functions
Chapter 22 Introducing VBA . . . . . . . . . . . . . . . . . . . . . . . . . 597
Chapter 23 Function Procedure Basics . . . . . . . . . . . . . . . . . . 609
Chapter 24 VBA Programming Concepts . . . . . . . . . . . . . . . . 629
Chapter 25 VBA Custom Function Examples . . . . . . . . . . . . . 663
Appendix A: Working with Imported
1-2-3 Files . . . . . . . . . . . . . . . . . . . 709
Appendix B: Excel Function Reference . . . . . . . . . 717
Appendix C: Using Custom Number Formats . . . . 735
Appendix D: Additional Excel Resources . . . . . . . . 761
Appendix E: What’s on the CD-ROM . . . . . . . . . . 769
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783
End-User License Agreement . . . . . . . . . . . . . . . . 829

Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Part I Basic Information
Chapter 1 Excel in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The History of Excel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
It Started with VisiCalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Then Came Lotus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Microsoft Enters the Picture . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Excel Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Object Model Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
The Workings of Workbooks . . . . . . . . . . . . . . . . . . . . . . . . . 8
Worksheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Chart Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
XLM Macro Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Dialog Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Excel’s User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Shortcut Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Smart Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Task Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Drag-and-Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Customized On-screen Display . . . . . . . . . . . . . . . . . . . . . . . . 14
Data Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Object and Cell Selecting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Excel’s Help System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Cell Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Numeric Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Stylistic Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Worksheet Formulas and Functions . . . . . . . . . . . . . . . . . . . 18
Objects on the Drawing Layer . . . . . . . . . . . . . . . . . . . . . . . 19
Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Linked Picture Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Dialog Box Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
xix
Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Customization in Excel . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Add-in Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Analysis Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Outlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Scenario Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Analysis ToolPak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Auditing Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Solver Add-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Protection Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Protecting Formulas from Being Overwritten . . . . . . . . . . . . . . 25
Protecting a Workbook’s Structure . . . . . . . . . . . . . . . . . . . . . 26
Chapter 2 Basic Facts about Formulas . . . . . . . . . . . . . . . . . . . . . . 29
Entering and Editing Formulas . . . . . . . . . . . . . . . . . . . . . . 29
Formula Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Entering a Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Pasting Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Spaces and Line Breaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Formula Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Sample Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Editing Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Using Operators in Formulas . . . . . . . . . . . . . . . . . . . . . . . . 35
Reference Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Sample Formulas That Use Operators . . . . . . . . . . . . . . . . . . . 36
Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Nested Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Calculating Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Cell and Range References . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Creating an Absolute Reference . . . . . . . . . . . . . . . . . . . . . . . 42
Referencing Other Sheets or Workbooks . . . . . . . . . . . . . . . . . . 43
Making an Exact Copy of a Formula . . . . . . . . . . . . . . . . . . 45
Converting Formulas to Values . . . . . . . . . . . . . . . . . . . . . . 46

Hiding Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Errors in Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Dealing with Circular References . . . . . . . . . . . . . . . . . . . . . 50
Goal Seeking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
A Goal-Seeking Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
More about Goal Seeking . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Chapter 3 Working with Names . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
What’s in a Name? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
xx Contents
Methods for Creating Cell and Range Names . . . . . . . . . . . . 56
Creating Names Using the Define Name Dialog Box . . . . . . . . . 56
Creating Names Using the Name Box . . . . . . . . . . . . . . . . . . . 57
Creating Names Automatically . . . . . . . . . . . . . . . . . . . . . . . . 58
Naming Entire Rows and Columns . . . . . . . . . . . . . . . . . . . . . 61
Names Created by Excel . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Creating Multisheet Names . . . . . . . . . . . . . . . . . . . . . . . . . 63
A Name’s Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Creating Worksheet-Level Names . . . . . . . . . . . . . . . . . . . . . . 65
Combining Worksheet- and Workbook-Level Names . . . . . . . . . 65
Referencing Names from Another Workbook . . . . . . . . . . . . . . 66
Working with Range and Cell Names . . . . . . . . . . . . . . . . . . 66
Creating a List of Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Using Names in Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Using the Intersection Operators with Names . . . . . . . . . . . . . . 69
Using the Range Operator with Names . . . . . . . . . . . . . . . . . . . 70
Referencing a Single Cell in a Multicell Named Range . . . . . . . . 70
Applying Names to Existing Formulas . . . . . . . . . . . . . . . . . . . 71
Applying Names Automatically When Creating a Formula . . . . . 72
Unapplying Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Deleting Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

Deleting Named Cells or Ranges . . . . . . . . . . . . . . . . . . . . . . . 73
Redefining Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Changing Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Viewing Named Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Using Names in Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
How Excel Maintains Cell and Range Names . . . . . . . . . . . . 75
Inserting a Row or Column . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Deleting a Row or Column . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Cutting and Pasting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Potential Problems with Names . . . . . . . . . . . . . . . . . . . . . . 75
Name Problems When Copying Sheets . . . . . . . . . . . . . . . . . . . 76
Name Problems When Deleting Sheets . . . . . . . . . . . . . . . . . . . 77
The Secret to Understanding Names . . . . . . . . . . . . . . . . . . 78
Naming Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Naming Text Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Using Worksheet Functions in Named Formulas . . . . . . . . . . . . 81
Using Cell and Range References in Named Formulas . . . . . . . . 82
Using Named Formulas with Relative References . . . . . . . . . . . 83
Advanced Techniques That Use Names . . . . . . . . . . . . . . . . 86
Using the INDIRECT Function with a Named Range . . . . . . . . . . 86
Using the INDIRECT Function to Create a Named Range
with a Fixed Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Using Arrays in Named Formulas . . . . . . . . . . . . . . . . . . . . . . 88
Creating a Dynamic Named Formula . . . . . . . . . . . . . . . . . . . . 89
Contents xxi
Part II Using Functions in Your Formulas
Chapter 4 Introducing Worksheet Functions . . . . . . . . . . . . . . . . 95
What Is a Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Simplify Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Perform Otherwise Impossible Calculations . . . . . . . . . . . . . . . 96

Speed Up Editing Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Provide Decision-Making Capability . . . . . . . . . . . . . . . . . . . . 97
More about Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Function Argument Types . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Names as Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Full-Column or Full-Row as Arguments . . . . . . . . . . . . . . . . . 100
Literal Values as Arguments . . . . . . . . . . . . . . . . . . . . . . . . . 100
Expressions as Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Other Functions as Arguments . . . . . . . . . . . . . . . . . . . . . . . 101
Arrays as Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Ways to Enter a Function into a Formula . . . . . . . . . . . . . 102
Entering a Function Manually . . . . . . . . . . . . . . . . . . . . . . . 102
Using the Insert Function Dialog Box to Enter a Function . . . . 103
More Tips for Entering Functions . . . . . . . . . . . . . . . . . . . . . 105
Function Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Financial Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Date & Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Math & Trig Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Statistical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Lookup and Reference Functions . . . . . . . . . . . . . . . . . . . . . 108
Database Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Text Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Logical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Information Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Engineering Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
User-Defined Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Other Function Categories . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Analysis ToolPak Functions . . . . . . . . . . . . . . . . . . . . . . . . . 110
Chapter 5 Manipulating Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
A Few Words about Text . . . . . . . . . . . . . . . . . . . . . . . . . . 111

How Many Characters in a Cell? . . . . . . . . . . . . . . . . . . . . . . 111
Numbers as Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Text Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Determining Whether a Cell Contains Text . . . . . . . . . . . . . . . 113
Working with Character Codes . . . . . . . . . . . . . . . . . . . . . . . 114
Determining Whether Two Strings Are Identical . . . . . . . . . . . 116
Joining Two or More Cells . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Displaying Formatted Values as Text . . . . . . . . . . . . . . . . . . . 118
Displaying Formatted Currency Values as Text . . . . . . . . . . . . 119
xxii Contents
Repeating a Character or String . . . . . . . . . . . . . . . . . . . . . . 120
Creating a Text Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Padding a Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Removing Excess Spaces and Nonprinting Characters . . . . . . . 122
Counting Characters in a String . . . . . . . . . . . . . . . . . . . . . . 123
Changing the Case of Text . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Extracting Characters from a String . . . . . . . . . . . . . . . . . . . 124
Replacing Text with Other Text . . . . . . . . . . . . . . . . . . . . . . . 125
Finding and Searching within a String . . . . . . . . . . . . . . . . . 126
Searching and Replacing within a String . . . . . . . . . . . . . . . . 127
Advanced Text Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Counting Specific Characters in a Cell . . . . . . . . . . . . . . . . . . 127
Counting the Occurrences of a Substring in a Cell . . . . . . . . . . 128
Expressing a Number as an Ordinal . . . . . . . . . . . . . . . . . . . . 128
Determining a Column Letter for a Column Number . . . . . . . . 129
Extracting a Filename from a Path Specification . . . . . . . . . . . 130
Extracting the First Word of a String . . . . . . . . . . . . . . . . . . . 130
Extracting the Last Word of a String . . . . . . . . . . . . . . . . . . . 130
Extracting All but the First Word of a String . . . . . . . . . . . . . 131
Extracting First Names, Middle Names, and Last Names . . . . . . 131

Removing Titles from Names . . . . . . . . . . . . . . . . . . . . . . . . 133
Counting the Number of Words in a Cell . . . . . . . . . . . . . . . . 133
Custom VBA Text Functions . . . . . . . . . . . . . . . . . . . . . . . 134
Chapter 6 Working with Dates and Times . . . . . . . . . . . . . . . . . 135
How Excel Handles Dates and Times . . . . . . . . . . . . . . . . . 135
Understanding Date Serial Numbers . . . . . . . . . . . . . . . . . . . 136
Entering Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Understanding Time Serial Numbers . . . . . . . . . . . . . . . . . . . 138
Entering Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Formatting Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . 141
Problems with Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Date-Related Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Displaying the Current Date . . . . . . . . . . . . . . . . . . . . . . . . . 146
Displaying Any Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Generating a Series of Dates . . . . . . . . . . . . . . . . . . . . . . . . 148
Converting a Non-Date String to a Date . . . . . . . . . . . . . . . . 149
Calculating the Number of Days between Two Dates . . . . . . . . 149
Calculating the Number of Work Days between Two Dates . . . . 150
Offsetting a Date Using Only Work Days . . . . . . . . . . . . . . . . 152
Calculating the Number of Years between Two Dates . . . . . . . . 152
Calculating a Person’s Age . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Determining the Day of the Year . . . . . . . . . . . . . . . . . . . . . . 154
Determining the Date of the Most Recent Sunday . . . . . . . . . . 155
Determining the First Day of the Week after a Date . . . . . . . . . 156
Contents xxiii

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×