15

Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive
Page 2: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

Excel® for Chemists

Second Edition

Page 3: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

This page intentionally left blank

Page 4: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

ExceL for ChemistsA Comprehensive Guide

Second Edition

E. Joseph BilloDepartment of Chemistry

Boston CollegeChestnut Hill, Massachusetts

New York • Chichester • Weinheim • Brisbane • Singapore • Toronto

Page 5: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

This text is printed on acid-free paper. ^9

Trademarks: Macintosh is a registered trademark of Apple Computer, Inc. Windows is aregistered trademark of Microsoft Corporation.

Copyright © 2001 by John Wiley & Sons, Inc. All rights reserved.

Published simultaneously in Canada.

No part of this publication may be reproduced, stored in a retrieval system or transmitted in anyform 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, withouteither the prior written permission of the Publisher, or authorization through payment of theappropriate per-copy fee to the Copyright Clearatnce Center, 222 Rosewood Drive, Danvers, MA01923, (978) 750-8400, fax (978) 750-4744. Requests to the Publisher for permission should beaddressed to the Permission Department, John Wiley & Sons, Inc., 605 Third Avenue, New York,NY 10158-0012, (212) 850-6011, fax (212) 850-6008, E-Mail: [email protected].

For ordering and customer service, call 1-800-CALL-WILEY.

Library of Congress Cataloging-in-Publication Data:

Billo, E. Joseph.Excel for chemists : a comprehensive guide / E. Joseph Billo.—2nd ed.

p. cm.Includes bibliographical references and index.ISBN 0-471-39462-9 (pbk.: acid-free paper)

1. Electronic spreadsheets. 2. Chemistry—Data processing. 3. Microsoft Excel(Computer file) I. Title.

QD39.3.S67 B55 2001542'.85'5369—dc21 2001024022

Printed in the United States of America.

1 0 9 8 7 6 5 4 3

Disclaimer: This eBook does not include the ancillary media that waspackaged with the original printed version of the book.

Page 6: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

SUMMARY OF CONTENTSPreface xixPreface to the First Edition xxiBefore You Begin xxiii

PART I THE BASICSChapter 1 Working with Excel 3Chapter 2 Creating Charts: An Introduction 47

PART II ADVANCED SPREADSHEET TOPICSChapter 3 Creating Advanced Worksheet Formulas 59Chapter 4 Creating Array Formulas 91Chapters Advanced Charting Techniques 109Chapter 6 Using Excel's Database Features 133Chapter 7 Importing Data into Excel 147Chapter 8 Adding Controls to a Spreadsheet 159

PART III SPREADSHEET MATHEMATICSChapter 9 Some Mathematical Tools For Spreadsheet Calculations 169Chapter 10 Graphical and Numerical Methods of Analysis 193Chapter 11 Linear Regression 207Chapter 12 Non-Linear Regression Using the Solver 223

PART IV EXCEL VISUAL BASIC MACROSChapter 13 Visual Basic for Applications: An Introduction 241Chapter 14 Programming with VBA 251Chapter 15 Working with Arrays in VBA 279Chapter 16 Creating Command Macros 291Chapter 17 Creating Custom Functions 299Chapter 18 Creating Custom Menus and Menu Bars 309Chapter 19 Creating Custom Toolbuttons and Toolbars 317

PART V SOME APPLICATIONSChapter 20 Analysis of Solution Equilibria 329Chapter 21 Analysis of Spectrophotometric Data 339Chapter 22 Calculation of Binding Constants 349Chapter 23 Analysis of Kinetics Data 373

PART VI APPENDICESAppendix A Selected Worksheet Functions by Category 391Appendix B Alphabetical List of Selected Worksheet Functions 397Appendix C Selected Visual Basic Keywords by Category 417Appendix D Alphabetical List of Selected Visual Basic Keywords 421Appendix E Shortcut Keys for PC and Macintosh 441Appendix F Selected Shortcut Keys by Category 457Appendix G About the CD-ROM That Accompanies This Book 463

INDEX 469

v

Page 7: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

This page intentionally left blank

Page 8: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

CONTENTSPreface xixPreface to the First Edition xxiBefore You Begin xxiii

PARTI: THE BASICS 1

Chapter 1 Working with Excel 3The Excel Document Window 3

Changing What Excel Displays 4Moving or Re-Sizing Documents (Windows) 5Moving or Re-Sizing Documents (Macintosh) 5

Navigating Around the Workbook 5Selecting Multiple Worksheets 6Changing Worksheet Names 6Rearranging the Order of Sheets in a Workbook 6

Navigating Around the Worksheet 7Selecting a Range of Cells on the Worksheet 7Selecting Non-Adjacent Ranges 8Selecting a Block of Cells 8

Entering Data in a Worksheet 9Entering Numbers 10How Excel Stores and Displays Numbers 10Entering Text 11Entering Formulas 11Adding a Text Box 12Entering a Cell Comment 12Editing Cell Entries 13

Excel's Menus: An Overview 13Shortcut Menus 15Menu Commands or Toolbuttons? 15

Opening, Closing and Saving Documents 15Opening or Creating Workbooks 15Using Move, Copy or Delete Sheet 16Using Close or Exit/Quit 16Using Save or Save As 16The Types of Excel Document 17Using Save Workspace 17

Printing Documents 18

vii

Page 9: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

viii Excel for Chemists

Using Page Setup 18Using Print Preview 19Using Print 19Printing a Selected Range of Cells in a Worksheet 20Printing Row or Column Headings for a Multi-Page Worksheet 21

Editing a Worksheet 21Inserting or Deleting Rows or Columns 21Using Cut, Copy and Paste 22Using Paste Special 22Using Paste Special to Transpose Rows and Columns 23Using Clear 24Using Insert 24To Copy, Cut or Paste Using Drag-and-Drop Editing 24Duplicating Values or Formulas in a Range of Cells 25Absolute, Relative and Mixed References 26Relative References When Using Copy and Cut 27Using AutoFill to Fill Down or Fill Right 27Using AutoFill to Create a Series 28

Formatting Worksheets 29Using Column Width and Row Height 29Using Alignment 30Using Font 31The Alternate Character Set 32Entering Subscripts and Superscripts 33Using Border and Patterns 33Using the Format Painter Toolbutton 34

Number Formatting 35Using Excel's Built-in Number Formats 35Custom Number Formats 36Variable Number Formats 38Conditional Number Formats 38Using the Number Formatting Toolbuttons 39Formatting Numbers Using "Precision as Displayed" 39

Protecting Data in Worksheets 40Using Protection 40Protecting a Workbook by Making it Read-Only 40

Controlling the Way Documents Are Displayed 41Viewing Several Worksheets at the Same Time 41Using New Window and Arrange 41Different Views of the Same Worksheet 42Using New Window 43Using Split 43Using Freeze Panes 44

Copying from Excel to Microsoft Word 44Using Copy and Paste 45

Page 10: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

Contents ix

Making a "Screen Shot" (Macintosh) 45Making a "Screen Shot" (Windows) 46

Useful References 46

Chapter 2 Creating Charts: An Introduction 47Only One Chart Type Is Useful for Chemists 47Creating a Chart 47

Creating a Chart Using the ChartWizard 47Activating, Resizing and Moving an Embedded Chart 50

Formatting Charts: An Introduction 50Using the Chart Menu 50Using Chart Type... to Switch From One Chart Type to Another 51Using Chart Options... to Add Titles, Gridlines or a Legend 51Using Location... to Move or Copy an Embedded Chart 51

Formatting the Elements of a Chart 51Selecting Chart Elements 52Formatting Chart Elements 52

PART II: ADVANCED SPREADSHEET TOPICS 57

Chapter 3 Creating Advanced Worksheet Formulas 59The Elements of a Worksheet Formula 59

Operators 59Absolute, Relative and Mixed References 60Creating and Using 3-D References 60Creating and Using External References 61Creating an External Reference by Selecting 62Creating an External Reference by Using Paste Link 62The External Reference Contains the Complete Directory Path 62Updating References and Re-Establishing Links 62

Entering Worksheet Formulas 63Using Names Instead of References 64

Using Define Name 64Using Create Names 65Using the Drop-Down Name List Box 67Entering a Name in a Formula by Selecting 67Using Apply Names 68Using Paste Name 68Deleting Names 68Changing a Name 69Names Can Be Local or Global 69The Label... Command 70Excel Will Create Labels Automatically 71

Worksheet Functions: An Overview 71Function Arguments 72

Page 11: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

x Excel for Chemists

Math and Trig Functions 72Functions for Working with Matrices 73

Statistical Functions 73Logical Functions 73

The IF Function 73Nested IF Functions 74AND, OR and NOT 76

Date and Time Functions 76Date and Time Arithmetic 78

Text Functions 78The LEN, LEFT, RIGHT and MID Functions 78The UPPER, LOWER and PROPER Functions 79The FIND, SEARCH, REPLACE, SUBSTITUTE and EXACT Functions 79The FIXED and TEXT Functions 80The VALUE Function 81The CODE and CHAR Functions 81

Lookup and Reference Functions 81The VLOOKUP and HLOOKUP Functions 82The LOOKUP Function 82The INDEX and MATCH Functions 82Using Wildcard Characters with MATCH, VLOOKUP or HLOOKUP 83The OFFSET Function 83

Using Insert Function 83A Shortcut to a Function 85

Creating "Megaformulas" 85Troubleshooting the Worksheet 87

Error Values and Their Meanings 87Examining Formulas 87Finding Dependent and Precedent Cells 88Using Paste List 88

Useful References 89

Chapter 4 Creating Array Formulas 91Using Array Formulas 91

Array Constants 93Editing or Deleting Arrays 94Formulas That Return an Array Result 94Creating a Three-Dimensional Array on a Single Worksheet 95

Evaluating Polynomials or Power Series Using Array Formulas 96Using the ROW Function in Array Formulas 97Using the INDIRECT Function in Array Formulas 97

Using Array Formulas to Work With Lists 97Counting Entries in a List Using Multiple Criteria 98

Page 12: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

Contents xi

Counting Common Entries in Two Lists 99Counting Duplicate Entries in a List 100Counting Unique Entries in a List 101Indicating Duplicate Entries in a List 101Returning an Array of Unique Entries in a List 103

Using an Array Formula to Sort a 1-D List 104Using an Array Formula to Sort a 2-D List 105

Chapter 5 Advanced Charting Techniques 109Good Charts vs. Bad Charts 109Charts with More Than One Data Series 110

Plotting Two Different Sets of Y Values in the Same Chart 110Plotting Two Different Sets of X and Y Values in the Same Chart 1llAnother Way to Plot Two Different Sets of X and Y Values 112

Extending a Data Series or Adding a New Series 114The Copy and Paste Method 114The Drag and Drop Method 114The Color-Coded Ranges Method 114Using Source Data... in the Chart Menu 116Editing the SERIES Function in the Formula Bar 116

Customizing Charts 116Plotting Experimental Data Points and a Calculated Curve 116Adding Error Bars to an XY Chart 118Adding Data Labels to an XY Chart 120Charts Suitable for Publication 121

Changing the Default Chart Format 121Logarithmic Charts 1223-D Charts 123

Using Excel's Built-in 3-D Chart Format 123Charts with Secondary Axes 124Getting Creative with Charts 126

A Chart with an Additional Axis 127A Chart with an Inset 129

Linking Chart Text Elements to a Worksheet 130To Switch Plotting Order in an XY Chart 131Some Chart Specifications (Excel 2000) 132

Chapter 6 Using Excel's Database Features 133The Structure of a List or Database 133Sorting a List 133

Sorting According to More Than One Field 135Sort Options 135

Using AutoFilter to Obtain a Subset of a List 136Using Multiple Data Filters 138

Defining and Using a Database 138

Page 13: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

xii Excel for Chemists

Creating a Database 138Defining a Database 139Adding or Deleting Records or Fields 139Updating a Database Using Data Form 139Finding Records That Meet Criteria 141Defining and Using Selection Criteria 141Using Multiple Criteria 142Special Criteria for Text Entries 143Extracting Records 144

Using Database Functions 145

Chapter 7 Getting Data into Excel 147Direct Input of Instrument Data into Excel 147Transferring Files from Other Applications to Excel 147

Using the Text Import Wizard 147Using Text to Columns 151

From Hard Copy (Paper) to Excel 151Using a Scanner to Transfer Numeric Data to Excel 151Using a Scanner to Transfer Graphical Data to Excel 154

Selecting Every Nth Data Point 154Using AutoFill 154Using the Sampling Tool 155Using a Worksheet Formula 157

Chapter 8 Adding Controls to a Spreadsheet 159You Can Add Option Buttons, Check Boxes, List Boxesand Other Controls to a Worksheet 159How to Add a Control to a Worksheet 160

Control Properties 161A List Box on a Worksheet 163A Drop-down List Box on a Worksheet 163Option Buttons and a Drop-down List Box 165

PART III: SPREADSHEET MATHEMATICS 167

Chapter 9 Some Mathematical Tools for Spreadsheet Calculations 169Looking Up Values in Tables 169

Getting Values from a One-Way Table 169Getting Values from a Two-Way Table 170

Interpolation Methods: Linear 171Table Lookup with Linear Interpolation 171

Interpolation Methods: Cubic 173Numerical Differentiation 175

First and Second Derivatives of a Data Set 175Derivatives of a Function 178

Numerical Integration 179

Page 14: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

Contents xii

An Example: Finding the Area Under a Curve 180Differential Equations 182

Euler's Method 183The Runge-Kutta Methods 184

Arrays, Matrices and Determinants 186An Introduction to Matrix Algebra 187

Polar to Cartesian Coordinates 189Useful Reference 191

Chapter 10 Graphical and Numerical Methods of Analysis 193Finding Roots of Equations 193

The Graphical Method 193The Method of Successive Approximations 194The Newton-Raphson Method 196

Solving a Problem Using Goal Seek 198Solving a Problem by Intentional Circular Reference 201Solving Sets of Simultaneous Linear Equations 203

Cramer's Rule 204Solution Using Matrix Inversion 205

Chapter 11 Linear Regression 207Least-Squares Curve Fitting 207

Least-Squares Fit to a Straight Line 208The SLOPE, INTERCEPT and RSQ Functions 208Linear Regression Using LINEST 209Least-Squares Fit of y = mx + b 211Regression Line Without an Intercept 211Weighted Least Squares 212

Multiple Linear Regression 212Linear Regression Using a Power Series 214Linear Regression Using Trendline 214Linear Regression Using the Analysis ToolPak 216

Using the Regression Statistics 218Testing Whether an Intercept Is Significantly Different from Zero 218Testing Whether Two Slopes Are Significantly Different 219Testing Whether a Regression Coefficient Is Significant 220Testing Whether Regression Coefficients Are Correlated 220Confidence Intervals for Slope and Intercept 221Confidence Limits and Prediction Limits for a Straight Line 221

Useful References 222

Chapter 12 Non-Linear Regression Using the Solver 223Non-Linear Functions 223Using the Solver to Perform Non-Linear Least-Squares Curve Fitting 224

Using the Solver for Optimization 224

Page 15: Excel® for Chemists › doc › af › 94 › af940779-3a13-4814-a0e5-… · Library of Congress Cataloging-in-Publication Data: Billo, E. Joseph. Excel for chemists : a comprehensive

xiv Excel for Chemists

Using the Solver for Least-Squares Curve Fitting 224Using the Solver: An Example 225Comparison with a Commercial Non-Linear Least-Squares Package 230Solver Options 231The "Use Automatic Scaling" Option is Important for Many ChemicalProblems 233

Statistics of Non-Linear Regression 233A Macro to Provide Regression Statistics for the Solver 235Using the SolvStat Macro 236An Additional Benefit from Using the SolvStat Macro 237

Useful References 238

PART IV: EXCEL VISUAL BASIC MACROS 239

Chapter 13 Visual Basic for Applications: An Introduction 241Visual Basic Procedures and Modules 241

There are Two Kinds of Macros 241The Structure of a Sub Procedure 242The Structure of a Function Procedure 242

The Visual Basic Editor 243Getting Started: Using the Recorder to Create a Sub Procedure 245

The Personal Macro Workbook 247Runninga Sub Procedure 247Assigning a Shortcut Key to a Sub Procedure 248

Getting Started: Creating a Simple Custom Function 248Using a Function Macro 249

Renaming a Macro 250How Do I Save a Macro? 250

Chapter 14 Programming with VBA 251Creating Visual Basic Code 251

Entering VBA Code 251Making a Reference to a Cell or Range of Cells 252Making a Reference to the Active Cell or a Selected Range of Cells 253Making a Reference to a Cell Other Than the Active Cell 253References Using the Union or Intersect Method 253Getting Values from a Worksheet 254Sending Values to a Worksheet 254

Components of Visual Basic Statements 254Operators 254Variables and Arguments 255

Objects, Properties and Methods 255Objects 256Some Useful Objects 257"Objects" That Are Really Properties 257