The O’Leary Series Microsoft Excel 2002 Lab 5 Using Data Tables, Creating Macros, and Designing Onscreen Forms McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 2 Objectives 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Use the PMT function. Use a data table. Add controls. Create a macro with the Visual Basic Editor. Create a macro with the Macro Recorder. Name a range. Use the IF function. Create a form. Add cell comments. Document a file. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 3 Concepts Overview 1. Data Table - A data table is a type of what-if analysis in which one or more variables are changed to see the effect on the formulas that include these variables. 2. Macro - A macro is a stored series of keystrokes and commands that are executed automatically when the macro is run. 3. Controls - Graphic objects that are designed to help the user interact with the worksheet. 4. Visual Basic Editor - The Visual Basic Editor is a tool used to write and edit macros attached to Excel workbooks. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 4 Concepts Overview 5. Macro Recorder - The Macro Recorder tool automatically creates a macro by recording a series of actions as macro commands. 6. Form - A form is a formatted worksheet with blank spaces that can be filled in online or on paper. 7. IF Function - The IF function checks to see if certain conditions are met and then takes action based on the results of the check. 8. Comments - Comments are notes attached to cells that can be used to clarify the meaning of the cell contents, provide documentation, or ask a question. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 5 Outline • Calculating a Loan Payment – Using the PMT Function • Using a Data Table – Creating a One Variable-Data Table • Automatically Formatting Worksheet Data – Applying an Autoformat McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 6 Outline • Automating Tasks with Macros – Changing the Macro Security Level – Creating a Command Button • Create a Macro Using the Visual Basic Editor – Running the Macro • Using the Macro Recorder – Editing a Macro McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 7 Outline • Creating a Form – Naming Ranges • Using the IF Function – Adding a Combo Box Control – Adding Comments • Finalizing the Form – Hiding Rows • Lab Review McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 8 Calculating a Loan Payment What would the monthly loan payments be for different down payments, interest rates, and repayment periods? McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 9 Using the PMT Function • Calculates a periodic payment on a loan • Value returned includes … – – – – Loan amount Interest (no taxes) Reserve payments Fees sometimes associated with loans McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 10 PMT Function • PMT(rate, npr, pv) – Three arguments: • Rate - interest rate of loan • Npr – total number of payments for the loan • Pv – amount of the loan, called the principal • Results displayed in the field containing the function McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 11 Concept 1: DATA TABLE • Shows the effect of using different values in a calculation • Used to calculate multiple what-if versions in one operation • Can view the results of all variations in the worksheet When would you use a data table? McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 12 Data Tables • One-variable data table – Contains one or more formulas – Each formula refers to one input cell – Input cell – a list of values • Column-oriented – listed down a column • Row-oriented – listed across a row • Example – varying interest rates McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 13 Data Tables cont. • Two-variable data table – Uses only one formula – Refers to two different input cells • One column-oriented and one row-oriented • Purpose of two-variable table – Shows the resulting effect on the formula when the values in both cells are modified • Example – varying interest rates and varying length of loan McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 14 Automatically Formatting Worksheet Data • Autoformat – A built-in combination of formats – Applied to a range of cells – Consist of a combination of formatting and enhancement options • Applying an Autoformat – Specify range of cells – Choose Format/Autoformat McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 15 Concept 2: MACRO • Stored series of keystrokes and commands • Stored actions run automatically when macro is executed • Useful for replacing a series of repeated commands • Macros range from simple to complex McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 16 More on Macros • Changing the Macro Security Level – Can contain viruses – Excel includes three levels of security • High • Medium - default • Low – Digital signature • Creating a Command button – A control added to a worksheet – Can be assigned to run a macro McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 17 Concept 3: CONTROLS • Graphic objects designed to help user interact with the worksheet • Used to… – Enter data – Perform an action – Make worksheet easier to read • Modified by changing properties McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 18 More on Controls • Examples – – – – Check boxes List boxes Option boxes Command buttons • Two ways to add to a worksheet – Forms toolbar – Control Toolbox toolbar McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 19 What is Visual Basic? • Programming language • Used to write and edit macros • Contains an editor for ease of use McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 20 Using Visual Basic • Entries – Statements – Sub procedure • Syntax – rules of "grammar" for programming – Object ("x").Property • Object – item statement will affect • Property – action taken on object McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 21 Visual Basic What does this Visual Basic statement mean? Range("C2:C10").Select McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 22 More on Macros • Plan a macro before creating it • Write out the steps for the macro • Try executing the steps manually McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 23 Creating a Macro Remarks Text to display in input box McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 24 Concept 5: MACRO RECORDER • Automatically creates a macro • Records a series of actions as macro commands • Easier than using Visual Basic Editor • Better to use for short procedures only McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 25 Macro Recorder • Choose Tools/Macro/Record New Macro • Enter a name • Choose a shortcut key McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 26 Concept 6: FORM • Formatted worksheet with blank spaces • Can be filled online – Color and shading are more effective online – Can contain formulas that calculate immediately upon data entry • Can be printed and completed McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 27 Naming Ranges in a Form Reference to active sheet McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 28 Using Labels to Create a Range Name Labels to the left of cells will be range names McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 29 Range Name Example In place of the cell reference in the Name box, the range name is displayed McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 30 Paste Name in Formula McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 31 Range Names Name used in place of cell reference McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 32 Concept 7: IF FUNCTION • A function that checks to see if certain conditions are met • Takes action based on the results of the check • IF(logical_test, value_if_true,value_if_false • Logical test argument asks the question "Does the entry in this cell meet the stated conditions?" McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 33 Logical Operators Symbol Meaning McGraw-Hill/Irwin = < > <= Equal to Less than Greater than Less than or equal to >= <> NOT Greater than or equal to Not equal to Logical NOT AND OR Logical AND Logical OR © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 34 Nested Function Second If statement McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 35 Combo Box McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 36 Concept 8: COMMENTS • Notes attached to the cells • Used to – Clarify meaning of data – Provide documentation – Ask a question • Adds instructions to a form McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 37 Comments on a Form Comments McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 38 Finalizing the Form • Add a command button – Use Control Toolbar – Record and assign a macro • Hide nonessential items – Format/Row/Hide • Unlock data entry areas and protect others • Document the worksheet – File/Properties McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 39 Documentation McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 40 Key Terms • Autoformat – A built-in combination of formats that can be applied to a range of cells. The autoformats consist of a combination of number formats, fonts and attributes, colors, patterns, borders, frames, and alignment settings. • Column-oriented - In a data table, the orientation of the data in a table down a column as opposed to across a row (row-oriented). • Comment - Notes attached to cells that can be used to help clarify the meaning of the data, provide documentation or ask a question. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 41 Key Terms • Control - Graphic objects that are designed to automate the process of completing information in a worksheet. • Data table - A type of what-if analysis where one or more variables are changed to see the effect on the formula or formulas that include these variables. • Digital Signature - An electronic encryption-based stamp of authentication that confirms the macro or document originated from the signer and has not been changed. • Form - A formatted worksheet that is designed to be completed by filling in data in the blank spaces. • If function - A function that checks to see if certain conditions are met and then takes action based upon the results of the check. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 42 Key Terms • Input cell - A cell in which a list of values is substituted to see the resulting effect on the related formulas. Input values can be listed down a column (column-oriented) or across a row (row-oriented). • Logical operator - Symbols used in formulas that compare values in two or more cells. • Macro - A stored series of keystrokes and commands. When the macro is executed or run, the stored actions are performed automatically. • Macro recorder - A tool used to create a macro by recording a series of actions as macro statements as they are performed. • Name -The name of a macro. A macro name must begin with a letter, cannot exceed 255 characters and cannot include a space or period or the following characters: ! @ & $ #. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 43 Key Terms • Nested function - A second argument in a function that is enclosed within its own set of parentheses. • Nper - In the PMT function, the nper argument is the total number of payments for the loan. • Object - An element such as a text box that can be added to a workbook and that can be selected, sized, and moved. In visual Basic, the object is the item that the statement will affect (such as a cell, cell range, worksheet, or workbook). The object is enclosed in parenthesis and surrounded in quotes. • One-variable data table - A one-variable data table can contain one or more formulas, and each formula refers to one input cell. An input cell is a cell in which a list of values is substituted to see the resulting effect on the related formulas. Input values can be listed down a column (column-oriented) or across a row (row-oriented). McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 44 Key Terms • Principal - In the PMT function, the principal or pv argument is the amount of the loan. • Property - In visual Basic Editor, the property is what you want to do to the object. The property consists of 'reserved words' that have special meaning and direct Excel to perform the specified action. • Pv - In the PMT function the pv argument is the amount of the loan, also referred to as the principal. • Rate - In the PMT function, the rate argument is the interest rate of the loan. • Remark Statement - Remark statements describe the macro and include overall procedural documentation. Remark statements always begin with an apostrophe, which tells Excel to ignore the information on that line. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 45 Key Terms • Row-oriented - In a data table, the orientation of the data in a table across a row as opposed to down a column (column-oriented). • Run - To execute the commands stored in the macro. • Statement - The types of information you enter into the Visual Basic Editor are called statements. • Sub procedure - In Visual Basic Editor, a Sub procedure begins with a statement that starts the macro and ends with one that closes the macro (an End Sub statement). Sub procedures can also include remarks about the macro (such as its name and purpose) and functions (such as returning values to the procedure). • Syntax - Rules of structure for entering all visual basic statements. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 46 Key Terms • Two-variable Data Table - A data table that uses only one formula that refers to two different input cells, one column-oriented and one row-oriented. The purpose of this table is to show the resulting effect on the formula when the values in both of these cells are changed. • Visual Basic Editor - A programming application used to write and edit macros attached to Excel workbooks. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 47 Discussion Questions 1. Discuss different ways in which a data table can be used. When would you use a one-variable data table? When would a two-variable table be more appropriate? 2. Discuss some spreadsheet functions that you could automate with a macro. Would it be more appropriate to use the Visual Basic Editor or the Macro Recorder to create each of these macros? 3. Discuss what range names are and when it is appropriate to use them. Give some examples. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 48 Frequently Asked Questions • I need a new car. Can Excel help me to calculate loan payments? • Data tables seem useful, but I am not sure of how to use one. What are they? • My worksheet looks plain and boring. Is there an automatic way in Excel to make it look more attractive? • Give examples of when a macro would be helpful. McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 49 Frequently Asked Questions • Why am I given a warning message when a workbook contains a macro? • What are check boxes, list boxes, and command buttons? • What is the difference between using the Macro Recorder and the Visual Basic Editor to create a macro? When would I use either one? McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 50 Frequently Asked Questions • What are the benefits of using an Excel form? • I understand that Excel cell ranges can have names. What is the benefit of assigning names to ranges? How are they used? • How does the IF function work? • What is the logical operator for "not equal to"? McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 51 Frequently Asked Questions • How can I create a combo box for a list of values? • When would I use Excel comments on a worksheet? McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 52 Web Links • USD Excel Tutorial – http://www.bamaed.ua.edu/bct100/100top5.htm • The MS Excel Knowdule: Tutorial – http://isds.bus.lsu.edu/cvoc/learn/introit/excel/ • Data Tables :PC Magazine – http://www.zdnet.com/pcmag/pctech/content/so lutions/ss1702a.htm • A Set Size Selection Macro – http://www.zdnet.com/pcmag/pctech/content/so lutions/ss1813a.htm McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved. The O’Leary Series 53 Web Links • It's IFFY – Using Excel's IF Function – http://www.yukonstaffdevelopment.com/Traini ngAndDev/comtips/MSExcel.htm#IT'S%20IFF Y • Visual Basic Explorer – http://www.vbexplorer.com/ • Microsoft Visual Basic – http://msdn.microsoft.com/vbasic/ McGraw-Hill/Irwin © 2002 The McGraw-Hill Companies, Inc. All rights reserved.