MICROSOFT EXCEL 2000 LEVEL 5 VBA PROGRAMMING INTRODUCTION
|
|
- Abner Warner
- 5 years ago
- Views:
Transcription
1 MICROSOFT EXCEL 2000 LEVEL 5 VBA PROGRAMMING INTRODUCTION
2 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) Student Edition LESSON 1 - RECORDING MACROS... 4 Working with Visual Basic Applications... 5 Defining Macros... 5 Recording a Macro... 6 Running a Macro... 7 Assigning a Shortcut Key... 8 Adding and Assigning a Custom Button... 9 Assigning a Macro to a Menu Deleting a Macro from a Menu Using Relative References Using Absolute References Editing a Macro Manually Recording a Personal Macro Viewing the Personal Macro Workbook Deleting a Personal Macro Exercise LESSON 2 - CREATING A MACRO BUTTON Using a Macro Button Creating a Macro Button Copying a Macro Button Formatting a Macro Button Moving/Sizing a Macro Button Deleting a Macro Button Exercise LESSON 3 - CONTROL STRUCTURES The If Then Control Structure The If Then Else Control Structure The Select Case Control Structure Exercise LESSON 4 - USING LOOPING CONTROL STRUCTURES Using a For Next Statement... 36
3 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros Using a Do Loop Statement Using a For Each Next Statement Exercise LESSON 5 - OBJECTS AND VARIABLES Variables and Assignment Statements Variable Types Msgbox Function Objects Methods and Properties Exercise LESSON 6 - INTERACTIVE MACROS Creating a Custom Message Box Creating a Custom Input Box Exercise APPENDIX I - COURSE CONSOLIDATION EXERCISES Course Consolidation Exercises Number Course Consolidation Exercises Number
4 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) LESSON 1 - RECORDING MACROS In this lesson, you will learn how to: Record and run a macro Assign a shortcut key Use relative and absolute references Assign a macro to a menu and a custom button Delete a macro from a menu Using the Personal Macro workbook
5 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros WORKING WITH VISUAL BASIC APPLICATIONS Discussion In Microsoft Excel 2000, you can use the computer programming language Microsoft Visual Basic Programming System, Applications Edition. In the manual, this language will be referred to as Visual Basic Applications (VBA). The word visual in Visual Basic refers to the way in which you develop the user interface for Excel. Buttons, dialog boxes, menus, and so forth are drawn on the screen. The word basic in Visual Basic Applications refers to the programming code you write; Visual Basic is a form of the programming language BASIC (Beginner s All-Purpose Symbolic Instruction Code). Visual Basic (VB) is a separate product and is not integrated with a specific application, such as Excel. When distributing VB code to users who do not have VB loaded on the machines, the code must be compiled into separate executable files. Code created in VBA can be run as part of the Excel applications, without a separate executable file. DEFINING MACROS Discussion A macro is a small program you can use to automatically perform frequently used operations. It contains all the commands, mouse movements, and user actions necessary to complete a task. Macros can save you considerable time because you can use them to automate many repetitive, time-consuming tasks. You can use macros for simple tasks you perform frequently or for complex tasks that require consistency. Excel macros are written in the Visual Basic for Applications programming language. The series of commands used in a macro are known as a procedure. Each procedure is given a name that is used to execute the macro. Each procedure is saved in a device called a module. This module is attached to the worksheet in which the macro was written. A module cannot be seen in the normal window view because it is hidden. You must use the Visual Basic Editor window to select a module and view and edit the macro commands. Procedures begin with either the word Sub or Function. With Sub procedures the word Sub is followed by the name of the macro and a left and right parenthesis, and end with the words End Sub. Sub procedures can also contain arguments.commands entered between these two lines are macro statements.
6 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) When you record a procedure, Visual Basic translates the menu choices and keystrokes into the macro statements. Comments may also be inserted into a procedure to add clarity. If you know Visual Basic, you can write a procedure yourself instead of using the macro recorder. RECORDING A MACRO Discussion A macro can be created using the macro recorder. You perform the steps you want to include in the macro and Excel records them into a macro procedure. The steps you perform are not recorded as simple Keystrokes. They are translated into the Visual Basic for Application programming language, which uses macro statements to replace your steps. When you record a macro, Excel opens a module that is attached to a worksheet. As you perform the Keystrokes for the macro, they are saved as Visual Basic language statements in the module. A module can contain more than one macro. During the macro recording process, you give the macro a name and provide descriptive information about the tasks that the macro performs. This information is entered in the Record Macro dialog box and appears as a comment in the module. Recording a macro Studying the Visual Basic macro statements that the recorder generates is an excellent way to get acquainted with the Visual Basic for Applications programming language. When Recording a macro a module is automatically created containing the VBA code. To Insert a new module use the Insert Menu and module or right click on the Project name and Insert module.
7 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros Macro names can be upto 255 characters long including numbers. They must not contain spaces and must begin with a letter. Procedures 1. Open the workbook. 2. Enable the macros. 3. Display the Visual Basic toolbar. 4. Click the Record Macro button on the Visual Basic toolbar. 5. Type a name for the macro (no spaces). 6. Select OK. 7. Record the first step of the macro. 8. Continue recording the steps of the macro. 9. Click the Stop Recording button on the Visual Basic toolbar. RUNNING A MACRO Discussion Macros are saved in modules with the workbooks in which they were written. Before you can run a macro, the workbook with the module containing the macro must be opened. When you select a macro name in the Macro dialog box, Excel performs the commands listed under the macro name in the module in sequence. Macros in any open workbook can be run from any other open workbook.
8 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) Running a macro You can also run macros by clicking the Run Macro button on the Visual Basic toolbar. Procedures 1. Open the workbook. 2. Open a workbook and enable the macros. 3. Select the Tools menu. 4. Point to the Macros command. 5. Select the Macros command. 6. Select the macro you want to run. 7. Select Run. ASSIGNING A SHORTCUT KEY Discussion You can assign a shortcut Key to a macro. When a macro has a shortcut Key, pressing the shortcut Key combination runs the macro. All macro shortcut Key combinations
9 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros consist of the [Ctrl] Key followed by a letter. Shortcut Keys are case sensitive. Therefore the shortcut Key [Ctrl+e] is not the same as the shortcut Key [Ctrl+Shift+E]. Shortcut Keys can be assigned before you record a macro by entering a shortcut Key in the Record Macro dialog box. You should avoid assigning shortcut Keys to macros that are the same as the standard Excel shortcuts (e.g., [Ctrl+B], [Ctrl+S]) because the standard Excel shortcuts will be overridden by the macro shortcuts. Procedures 1. Open the workbook. 2. Enable the macros. 3. Select the Tools menu. 4. Point to the Macro command. 5. Select the Macros command. 6. Select the name of the macro to which you want to assign the shortcut Key. 7. Select Options. 8. Type a letter. 9. Select OK. 10. Select the Close button in the Macro dialog box. ADDING AND ASSIGNING A CUSTOM BUTTON Discussion In addition to the buttons that execute commands, Excel provides several generic buttons you can customise by attaching a macro. These buttons are listed in the Commands list box in the Customise dialog box.
10 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) Procedures 1. Open the workbook. 2. Create a custom toolbar. 3. Display the toolbar shortcut menu. 4. Select the Customise command. 5. Select the Commands tab. 6. Select the desired category from the Categories list box. 7. Select the desired command and button you want to appear on the toolbar from the Commands list box. 8. Drag the desired button onto the custom toolbar. 9. If a different button image is required, select the Modify Selection button, select Change Button Image and choose the required image. 10. Select Close. 11. Click the button on the toolbar. 12. Select the required macro name in the Assign Macro dialog box. 13. Select OK. ASSIGNING A MACRO TO A MENU Discussion You can assign a macro to a menu. You can choose in which menu you want the macro to appear. The macro appears as a menu command item to which you can give a specific name. Whenever the workbook containing the macro is opened, you can execute the macro, just as you would execute any standard menu command. It may be necessary to move the Customise dialog box in order to drag Custom Menu Item from the Commands list box to the desired location on the menu.
11 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros Procedures 1. Open the workbook. 2. Enable the macros. 3. Click the right mouse button on any toolbar. 4. Select the Customise command. 5. Select the Commands tab. 6. Select Macros from the Categories list box. 7. Select the required menu. 8. Drag Custom Menu Item from the Commands list box to the desired position on the menu. 9. Release the mouse button. 10. Select Modify Selection in the Customise dialog box. 11. Select the text in the Name text box. 12. Type the new name for the custom item. 13. Select Close. 14. Select the custom item name from the menu you assigned it 15. Select the required macro name in the Assign Macro dialog box. 16. Select OK. DELETING A MACRO FROM A MENU Discussion Once you assign a macro to a menu item, the macro is available for all worksheets. If you no longer want to access the macro from the menu, the menu item can be deleted. Macro items can also be deleted from menus by selecting the Customise dialog box, and dragging the macro name off of the menu.
12 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) Procedures 1. Open the workbook. 2. Enable the macros. 3. Click the right mouse button on any toolbar. 4. Select the Customise command. 5. Select the menu containing the macro you want to delete. 6. Select the macro you want to delete. 7. Select Modify Selection. 8. Select the Delete command. 9. Select Close. USING RELATIVE REFERENCES Discussion Absolute and relative references describe how the macro records the cell locations you are using in the worksheet. If you are using relative references, Excel records cell locations relative to the cell from which you start the macro. For example, if you enter the label Annual Sales Report with relative referencing, you can reproduce this label in any cell of any worksheet by activating a cell and running the macro. Relative references give the macro more flexibility. Procedures 1. Open the workbook. 2. Enable the macros. 3. Display the Visual Basic toolbar. 4. Click the Record Macro button on the Visual Basic toolbar. 5. Type a name for the macro. 6. Select OK.
13 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros 7. Click the Relative Reference button on the Stop Recording toolbar. 8. Record the steps of the macro. 9. Click the Stop Recording button on the Visual Basic toolbar. USING ABSOLUTE REFERENCES Discussion Absolute and relative references describe how the macro records the cell locations you are using in the worksheet. If you are using absolute references, Excel records the absolute or exact locations of cells. For example, if, while recording, you enter the label Annual Sales Report in cell A4, this label will always appears in cell A4 in a worksheet when you execute the macro. Procedures 1. Open the workbook. 2. Enable the macros. 3. Display the Visual Basic toolbar. 4. Click the Record Macro button on the Visual Basic toolbar. 5. Type a name for the macro. 6. Select OK. 7. Ensure the Relative Reference button on the Stop Recording toolbar is deactivated. 8. Record the steps of the macro. 9. Click the Stop Recording button on the Visual Basic toolbar.
14 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) EDITING A MACRO MANUALLY Discussion Depending on the changes you need to make, it may be easier to make minor changes to a module using standard editing techniques rather than deleting the entire macro and recording it again. Using these standard-editing techniques, you can make changes to text that is entered as part of a macro. You can edit a macro manually, just as you would edit any other document text. You simply locate the macro in the module and add, change, or delete the individual macro step or portions of the macro steps as desired. Editing a macro manually It is important that you edit only the portions of the macro with which you are familiar. If you do not use the correct syntax and punctuation for the command statements, the macro may work incorrectly or not at all. Procedures 1. Open the workbook. 2. Enable the macros. 3. Select the Tools menu. 4. Point to the Macro command.
15 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros 5. Select the Macros command. 6. Select the macro you want to edit. 7. Select Edit to open the Visual Basic Editor window and locate the macro. 8. Select the text you want to change. 9. Type the new text. 10. Close the Visual Basic Editor window. RECORDING A PERSONAL MACRO Discussion By default, macros are recorded into modules attached to the current workbooks. While a workbook containing macros is open, the macros are available to all other open workbooks. However, if the workbook is closed, its macros are unavailable. The Personal Macro Workbook allows you to create macros that are available to all workbooks. The Personal Macro Workbook is a hidden file named Personal.xls. The Personal file is created automatically the first time you record a macro into it and is saved in the XLSTART folder under the folder in which Excel is installed. Workbooks saved in the XLSTART folder are opened automatically each time you start Excel. The Personal Macro Workbook is hidden so that it is not accidentally edited, closed, or deleted. You must unhide the Personal file in order to edit the macros contained in it. By recording macros that perform common tasks, such as changing print options in the Personal Macro Workbook, the macros are available for use with all workbooks. After the Personal file is created, it is hidden by default. After you record a macro to the Personal file, you cannot see the Personal file unless you unhide it. You see the results of the macro you created, but they are in a standard workbook Excel creates, such as Book1, Book2, Book3, etc. Recording a personal macro
16 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) Procedures 1. Create a new, blank workbook. 2. Display the Visual Basic toolbar. 3. Click the Record Macro button on the Visual Basic toolbar. 4. Type the name of the macro. 5. Select the Store macro in list. 6. Select Personal Macro Workbook. 7. Select OK. 8. Record the steps of the macro. VIEWING THE PERSONAL MACRO WORKBOOK Discussion Once a macro has been created and stored in the Personal Macro Workbook, it can be viewed and edited. However, to view the Personal Macro Workbook, you must unhide the Personal file. Once the Personal file is no longer hidden, you can open the Visual Basic Editor window and make any desired revisions to the macro. Procedures 1. Display the Visual Basic toolbar. 2. Create a personal macro using the Record Macro button on the Visual Basic toolbar. 3. Select the Window menu. 4. Select the Unhide command. 5. Select Personal from the Unhide workbook list box. 6. Select OK.
17 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros 7. Select the Visual Basic Editor button on the Visual Basic toolbar. DELETING A PERSONAL MACRO Discussion You can delete any macro that is no longer needed or any macro that does not work. This option prevents you from using outdated macros. You must open the workbook containing the desired macro in order to delete it. If you want to delete macros in the Personal Macro Workbook, you must first unhide the workbook. If you delete the last macro in a module, the module itself still remains in the workbook. If you no longer need the module, you must delete the module manually. Procedures 1. Display the Visual Basic toolbar. 2. Create a personal macro using the Record Macro button on the Visual Basic toolbar. 3. Unhide the Personal Macro Workbook. 4. Select the Tools menu. 5. Point to the Macro command. 6. Select the Macros command. 7. Select the macro you want to delete. 8. Select Delete. 9. Select Yes.
18 Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) EXERCISE RECORDING MACROS Task Record a macro. Assign the macro to a menu. Assign a shortcut Key to a macro. Record a relative reference macro. Delete a macro from the menu. 1. Open Exercise Record a personal macro. Call it Report_Setup. 3. In the Page Setup dialog box, select the Landscape and Fit to page(s) options on the Page page. On the Margins page, change the top and bottom margins to.75, and centre the page horizontally and vertically. On the Header/Footer page, enter the centred custom header Sales Report. 4. Assign the Report_Setup macro to the Tools menu. Call it Report Page Setup. 5. Switch to the 1995 worksheet. Preview the worksheet. Close the Preview window. 6. Use the new Report Page Setup command on the Tools menu to run the page setup macro on the 1995 worksheet. Preview the worksheet again. Notice that the macro has been executed. Close the Preview window. 7. Switch to the 1994 worksheet. 8. Record a relative reference macro called Today which inserts today s date in a cell using the =today() function. 9. Stop recording the macro. 10. Switch to the 1995 worksheet. Select any cell and run the Today macro. 11. Assign the shortcut Key [Ctrl+t] to the Today macro. 12. Use the shortcut Key to run the Today macro. 13. Edit the Report Page Setup macro by changing the header to read Annual Sales Report rather than Sales Report. 14. Run the Report Page Setup macro again in the 1994 worksheet. Preview the worksheet again to check the macro has been amended.
19 Excel 2000: Level 5 (VBA Programming) Lesson 1 - Recording Macros 15. Delete the Report Page Setup macro from the Tools menu. Close the Customise dialog box. 16. Save and close the workbook.
20
21 LESSON 2 - CREATING A MACRO BUTTON In this lesson, you will learn how to: Create a macro button Copy a macro button Format a macro button Delete a macro button
22 Lesson 2 Creating a Macro Button Excel 2000: Level 5 (VBA Programming) USING A MACRO BUTTON Discussion You can create macro buttons in a worksheet that, when clicked, runs a particular macro. Macro buttons can simplify your work, automate repetitive tasks, or help an inexperienced user perform various worksheet tasks. You can draw macro buttons anywhere on a worksheet. Like other graphic objects, macro buttons float above the worksheet. You can create as many macro buttons as desired to perform a number of different tasks. Procedures 1. Open the workbook. 2. Enable the macros. 3. Click the macro button. CREATING A MACRO BUTTON Discussion You create a macro button on a worksheet using the Forms toolbar. You can also size the macro button and position it anywhere on the worksheet. After you draw the button, the Assign Macro dialog box opens in which you assign a macro to the button. When the button is clicked, the macro attached to the button runs.
23 Excel 2000: Level 5 (VBA Programming) Lesson 2 - Creating a Macro Button Creating a macro button Procedures 1. Open the workbook. 2. Enable the macros. 3. Display the Forms toolbar. 4. Click the Button button on the Forms toolbar. 5. Drag to create a button. 6. Release the mouse button. 7. Select the macro you want to assign to the button. 8. Select OK. 9. Drag to select the text on the button. 10. Release the mouse button. 11. Type the new text. 12. Deselect the button.
24 Lesson 2 Creating a Macro Button Excel 2000: Level 5 (VBA Programming) COPYING A MACRO BUTTON Discussion You can create macro buttons quickly by copying existing ones. This option is useful if you need several similar macro buttons on a worksheet. When you copy macro buttons, you can ensure that the buttons are the same size and shape. Copying a macro button Procedures 1. Open the workbook. 2. Enable the macros. 3. Hold [Ctrl] and position the mouse pointer over the button you want to copy. 4. Drag a copy of the button to the desired location. 5. Release the mouse button and then release [Ctrl]. 6. Deselect the button.
25 Excel 2000: Level 5 (VBA Programming) Lesson 2 - Creating a Macro Button 7. Click the right mouse button on a copy of the button to display the shortcut menu. 8. Select the Assign Macro command. 9. Select the macro you want to assign to the button. 10. Select OK. 11. Drag to select the text on the button. 12 Release the mouse button. 13. Type the new text. 14. Deselect the button. FORMATTING A MACRO BUTTON Discussion You can format text on a macro button in much the same way that you format text on a worksheet. You select the entire button and format all the text or just selected text. To select a macro button for editing, hold the [Ctrl] Key and click it. Otherwise, the macro attached to the button runs when you click the button. Procedures 1. Open the workbook. 2. Enable the macros. 3. To format all the button text, hold [Ctrl], click the macro button to select it, and release [Ctrl]. 4. Select the desired formatting option. 5. To format selected button text, hold [Ctrl], click the macro button to select it, and release [Ctrl]. 6. Select the text you want to format. 7. Select the desired formatting option. 8. Deselect the button.
26 Lesson 2 Creating a Macro Button Excel 2000: Level 5 (VBA Programming) MOVING/SIZING A MACRO BUTTON Discussion You can move or size a macro button the same way that you move or size a graphic object on a worksheet. In order to move or size a macro button, you must first select it. Moving and sizing a macro button To select a macro button for moving or sizing, you hold the [Ctrl] Key, click the desired macro button, and release the [Ctrl] Key. If you do not select the button first (if selection handles do not appear around the button), the macro attached to the button runs when you click it. Procedures 1. Open the workbook. 2. Enable the macros.
27 Excel 2000: Level 5 (VBA Programming) Lesson 2 - Creating a Macro Button 3. To move the macro button, hold [Ctrl], click the button to select it, and release [Ctrl]. 4. Point to the button you want to move. 5. Drag the button to a new position on the worksheet. 6. Release the mouse button. 7. To size the macro button, hold [Ctrl], click the button to select it, and release [Ctrl]. 8. Point to the button you want to size. 9. Drag one of the handles to size the button. 10. Release the mouse button. Click in any cell to deselect. DELETING A MACRO BUTTON Discussion You can delete any macro buttons you no longer need. This option prevents you from accidentally using macros that no longer work correctly. When you delete a macro button, only the button itself is deleted. The attached macro is not deleted. Procedures 1. Open the workbook. 2. Enable the macros. 3. Hold [Ctrl], click the macro button to select it, and release [Ctrl]. 4. Press [Delete].
28 Lesson 2 Creating a Macro Button Excel 2000: Level 5 (VBA Programming) EXERCISE CREATING A MACRO BUTTON Task Add a macro button to a worksheet. Then, copy, format, move, and size macro buttons. 1. Open Exercise Enable the macros. 3. Display the Forms and Visual Basic toolbars. Draw a button in the range G1:H3. 4. Assign the Date_Entry macro to the button. 5. Name the button Create Sheet. 6. Italicise and bold the text in the button. 7. Test the button. 8. Copy the button so that the top left corner of it is in cell G5. Rename the copied button Preview. Click in a blank cell to deselect the button. 9. Record a macro that previews and zooms into the worksheet. Call the macro Preview. Make sure that you store it into the current workbook. 10. Assign the Preview macro to the Preview button. 11. Test the button. Close the Preview window. 12. Move the Create Sheet button below the Preview button so that the top left corner of it is in cell G Reduce the size of the Create Sheet. 14. Close the Forms and Visual Basic toolbars. 15. Save and close the workbook.
29 LESSON 3 - CONTROL STRUCTURES In this lesson, you will learn how to: Altering flow using the If-Then control structure Altering flow using the If-Then-Else Control Structure Use the Select Case Control Structure to selectively alter the flow of execution
30 Lesson 3 Control Structures Excel 2000: Level 5 (VBA Programming) THE IF THEN CONTROL STRUCTURE Discussion The If-Then Control Structure enables you to test a condition altering execution flow based on the results of the condition, being true or if the condition is false. Control structures usually contain conditional statements. Conditional statements evaluate a particular condition, and then depending on that condition executes statements. The condition can be an expression. Such as If a Sales figure were over a certain amount, the statement would perform certain actions. This comparison operator to be used in this example would be a >. Microsoft Office together with VBA supports the following comparison operators. Symbol Operator < Less than <= Less than or equal to > Greater than >= Greater than or equal to = Equal to <> Not equal to You can use the single-line form for short, simple tests. However, the block form provides more structure and flexibility than the single-line form. Using block form makes it easier to read, maintain, and debug. If you use the single line form all statements must be on the same line and separated by colons, as in the following example: If ActiveCell > 10 Then Selection.Font.Bold = True: Selection.Font.Italic = True The structure for If-then would be either: If condition Then statement to perform : statement to perform Or: If condition Then Statements to perform if condition is true End If In this instance the statements will only be performed if the condition is true otherwise execution continues with any statements that may occur after the End If statement.
31 Excel 2000: Level 5 (VBA Programming) Lesson 3 Control Structures Procedures 1. Open the workbook. 2. Record a new macro. 3. Record one action. 4. Click the Bold button on the Formatting toolbar. 5. Stop recording. 6. Edit macro. 7. Type the desired code. THE IF THEN ELSE CONTROL STRUCTURE Discussion The syntax of the If Then Else control structure is: If condition Then Statements to perform if condition is true Else Statements to perform if condition is false Endif The single-line syntax or the multiple-line "Block" syntax can be used to create If Then Else statements. When Visual Basic meets the If statement it evaluates the condition as true or false. If the condition is evaluated as true, the statements that follow the If are executed until the Else statement is met. Execution will then continue with code if any, after the End If statement. If the condition is evaluated as false, Visual Basic will search for the Else statement and continue execution of code until it reaches the End if statement. If several conditions are to be evaluated a series of ElseIF statements can be included. The syntax is as follows: If condition1 Then
32 Lesson 3 Control Structures Excel 2000: Level 5 (VBA Programming) Statements to be performed if condition1 is true ElseIf condition2 Then Statements to be performed if condition2 is true ElseIf condition3 Then Statements to be performed if condition3 is true ElseIf Else Statements to be performed if no conditions are true End If Visual Basic evaluates condition1. If condition1 is true Visual Basic executes the statements following the If statement until it meets an ElseIf, Else or End If statement at which point control is passed to the statements after the End If. If condition1 is not true Visual Basic evaluates condition2, and then condition3, and so on until a condition is true. Procedures 1. Open the workbook. 2. Record a new macro. 3. Record one action. 4. Click the Italic button on the Formatting toolbar. 5. Stop recording. 6. Edit macro. 7. Type the desired code. THE SELECT CASE CONTROL STRUCTURE Discussion Select Case can be used as an alternative to If Then ElseIf where several conditions may need to be evaluated. This often seen as a more efficient way of coding, where multiple conditions need to be evaluated. For Select Case the same
33 Excel 2000: Level 5 (VBA Programming) Lesson 3 Control Structures expression has to be evaluated in every instance whereas for If..Then ElseIf each condition can involve different variables. The syntax of the Select Case control structure is: Select Case expression Case value1 Statements Case value2 Statements Case Else Statements End Select A single expression is evaluated at the top of the Case structure. Each case is then checked for this value, and the appropriate statements executed. Control is then passed to the statement after the End Select statement. If no Case statement holds the evaluated value then the statements after the Case Else statements are executed. Case Else is optional. Procedures 1. Open the workbook. 2. Switch to the Visual Basic Editor. 3. Type new procedure in module1. 4. Run new procedure
34 Lesson 3 Control Structures Excel 2000: Level 5 (VBA Programming) EXERCISE EXAMINING AND EDITING CODE Task To examine existing code, amend and run. 1. Open Practice Decision.xls. 2. Enable the macros. 3. Examine the procedure Re_Furb in Module1. This procedure requires VBA Code. 4. On the Holiday Destinations Sheet, column I (STATUS) requires text entries of either Refurbish or OK. 5. Add the relevant code, (record if you wish) that will: Tip! a) Check column H (dates) and if the last refurbish date was more than 5 years ago, then. b) Place text in Column I stating Refurbish, Otherwise... Place text in Column I stating OK Look in VBA help for Using Date data types. 6. Run the Re_Furb macro on cells H3 to H27. (Each cell needs to be done separately). 7. Save the file as My Practice Decision.xls and close the file.
35 LESSON 4 - USING LOOPING CONTROL STRUCTURES In this lesson, you will learn how to: Learn the control structure of, and create, a For Next loop. Learn the control structure of, and create, a Do Loop. Learn the control structure of, and create, a For Each Next loop.
36 Lesson 4 Using Loop Structures Excel 2000: Level 5 (VBA Programming) USING A FOR NEXT STATEMENT Discussion Within Excel 2000 Visual Basic for Applications you can create loops. Looping control structures within Visual Basic for Applications will enable the use of repeating operations, many times, based upon: A condition stating when the loop should stop. A fixed amount, stating how many times the loop runs. A selection of objects. The For Next control structure allows a series of statements to be repeated a given number of times. The syntax of the For Next control structure is: For variable = start To end Step step Statements Next variable The structure repeats the statements for a number of times depending on the values of start, end and step. Variable is a made-up name (naming rules apply), which holds a number, the variable name is set to equal start, and each time the statements are run, the variable name increments by the value of step. If step is omitted then, the increment will default to one. Procedures 1. Open Workbook. 2. Switch to the Visual Basic Editor. 3. View Code in Module. 4. Amend Code.
37 Excel 2000: Level 5 (VBA Programming) Lesson 4 Using Loop Structures USING A DO LOOP STATEMENT Discussion A Do Loop is used to run a block of statements while a condition is True or until a condition becomes True. The While Keyword checks a condition in a Do Loop statement: Check the condition before entering the loop. If the condition is false the contents of the loop will never execute. The syntax for this loop would be: Do While condition Statements Loop There are two ways to use the until Keyword to check a condition in a Do Loop statement. Check the condition before entering the loop. If the condition is false the contents of the loop will never execute. The syntax for this loop would be: Do Until condition statements Loop To stop an endless loop press Esc or Ctrl + Break. Procedures 1. Open Workbook. 2. Switch to the Visual Basic Editor. 3. View Code in Module. 4. Amend Code.
38 Lesson 4 Using Loop Structures Excel 2000: Level 5 (VBA Programming) USING A FOR EACH NEXT STATEMENT Discussion The For Each...Next structure repeats the statements for each element in an array or collection. The syntax of the For Each Next structure would be: For Each element In group Statements Next If there is at least one element in the group, the loop is entered into. The loop will continue to execute for each element. Nesting is also available with any loop control structure, placing one within another. Each loop element must be unique. Procedures 1. Open Workbook. 2. Switch to the Visual Basic Editor. 3. View Procedure in Module. 4. Add a Loop structure to change the Title in all worsheets.
39 Excel 2000: Level 5 (VBA Programming) Lesson 4 Using Loop Structures EXERCISE LOOPS Task To create a loop structure. 1. Open Practice Loops. 2. Enable the macros. 3. On Sheet 1, verify that cell C5 is selected 4. From the Macro dialog box, notice the macro Sub On_Dept() Add code to the macro On_Dept. If the activecell is equal to "Sales" then the Name to the left of the activecell is formatted as bold. 5. Run the On_Dept macro. 6. With cell C6 selected, run the On_Dept macro again, seeing what happens if the active cell does not contain "Sales" 7. Create any Loop structure and amend the code accordingly. This code should then run through all the cells C5:C Select cell C5 on Sheet1 and run the On_Dept macro 9. Save the file as My Practice Loops and close the file
40
41 LESSON 5 - OBJECTS AND VARIABLES In this lesson, you will learn how to: Create variables and learn how to assign values to them Examine why variables have different types and use the MsgBox statement Use Excel objects, properties and methods
42 Lesson 5 Objects and Variables Excel 2000: Level 5 (VBA Programming) VARIABLES AND ASSIGNMENT STATEMENTS Discussion At some point during coding within, Microsoft Excel Visual Basic for Applications, a variable may be required. Variables are used to hold information temporarily whilst a procedure is running. The information is then used at some point, or on many occasions during the procedure. Information held in variables is lost at the end of the procedure, unless the information is stored elsewhere. There are a few possibilities for storing information permanently outside of a variable. One such possibility would be: Use the value property of a range object, to store information in worksheet cells. For example the following statement transfers the contents of the variable Uname to the cell A1. Range( A1 ).value = Uname Assigning a variable a value can be done by: Assigning the variable a value from a cell on a worksheet. Give the variable a value, either at coding time or via user interaction. To assign a variable a value. For example, say we had a variable named Amnt, and we wanted to assign a value of 3. The following statement would be as follows: Amnt = 3 Variable names can be more or less, any combination of characters and numbers. However certain Naming conventions should apply:- Variable names must start with a letter Variable names should be named without underscores, hyphens or other unusual characters such as: ) ( /? \ [ ] { + = & $ or # Names must be no longer than 255 characters Avoid using conflicting names, such as, Name, Caption and Size. A mixture of different letter case, should be used to show word breaks. Such as DateStarted
43 Excel 2000: Level 5 (VBA Programming) Lesson 5 Objects and Variables Procedures 1. Open new workbook. 2. Switch to the Visual Basic Editor. 3. Insert module 4. Type new procedure in module1. 5. Run new procedure VARIABLE TYPES Discussion The data type of a variable determines, the type of data the variable will hold or can hold. For example a variable could hold a date, an integer (whole number) or a string, often seen as hello my name is. Although not required, to specify that a variable will hold certain data. A declaration is needed, in the form of a Dim statement. The syntax for declaring a data type to a variable is: Dim variable As type If a data type is not specified the variable will default to a variant data type. A variable that has been set as a variant data type can hold all kinds of data, such as: Character text Numeric Dates During a procedure the variable may be assigned different values. The last assignment will determine the data type of the variable. If a specific data type is assigned to a variable, the variable will only be able to hold that type of data.
44 Lesson 5 Objects and Variables Excel 2000: Level 5 (VBA Programming) The following provides a comprehensive list of the available data types. Data Type Range Byte 0 to 255 Boolean True or False Integer -32,768 to 32,767 Long (long integer) -2,147,483,648 to 2,147,483,647 Single(single-precision -3,402823E38 to E-45 for negative floating-point) values; E-45 to E38 for positive Double (double- precision floating point) values E308 to E- 324 for negative values; E-324 to E308 for positive values Currency (scaled integer) -922,337,203,685, to 922,337,203,685, Date January 1, 100 to December 31, 9999 Decimal Object String (variable-length) Variant User-defined (using Type) +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; +/ with 28 places to the right of the decimal; smallest non-zero number is +/ Any Object reference 0 to approximately 2 billion Any numeric value up to the range of a Double The range of each element is the same as the range of its data type. MSGBOX FUNCTION Discussion To display brief messages such as errors, warnings, or directions for accomplishing a task, you can use the MsgBox statement. This function displays a message in a dialog box, along with an OK button. Procedures 1. Open Workbook.
45 Excel 2000: Level 5 (VBA Programming) Lesson 5 Objects and Variables 2. Switch to the Visual Basic Editor. 3. Add a new Macro to existing Module. 4. Add new code. 5. Run new procedure. OBJECTS METHODS AND PROPERTIES Discussion An object is something that is controlled by Visual Basic for Applications, for example a worksheet or a range of cells. An object is controlled by using methods and properties. A property is a characteristic of the object that can be set in a particular way. For example a Font has many properties, such as, size, colour, bold, italic etc; a range of cells has a height property. A method is an action that can be performed by the object. For example, a worksheet has an insert method; to insert rows or worksheets. Properties have values that are returned or set. The reference to an object is followed by a period (.), the property name, an equal sign (=), and the new property value. For example: Selection.Font.Bold = True Returning the value of an item may be required. For example, testing to see if a cell contains a value. By using the value property, as shown in the following example: Sub Test_Cell() If ActiveCell.Value = "" Then ActiveCell.Value = 100 End If End Sub A method that doesn t take arguments is written: Object.Method For example, to justify a range of cells called data: Data.Justify
46 Lesson 5 Objects and Variables Excel 2000: Level 5 (VBA Programming) Procedures 1. Open New Workbook. 2. Switch to the Visual Basic Editor. 3. Add a new Module. 4. Open the Immediate window. 5. Test with lines of code
47 Excel 2000: Level 5 (VBA Programming) Lesson 5 Objects and Variables EXERCISE USING VARIABLES Task To assign values to variables. 1. Open Practice Lottery. 2. Enable the macros. 3. Examine the Lottery Members Worksheet. 4. The Worksheet is Printed every five weeks. 5. Using the ChangeDate macro, which is assigned to the Button. 6. Create the necessary code with variables, which will update the dates in cells H3 and H5 by five weeks. 7. Use the dates already typed in cells M8:O9 to check your answers. 8. Save the file as My Practice Lottery and close the file.
48 LESSON 6 - INTERACTIVE MACROS In this lesson, you will learn how to: Create a Sub procedure that displays information on a worksheet by using the MsgBox function. Create a Sub procedure that displays a dialog box by using an InputBox function WWP Training Limited Page 48
49 Excel 2000: Level 5 (VBA Programming) Lesson 6 Interactive Macros CREATING A CUSTOM MESSAGE BOX Discussion The syntax of the Msgbox function is: MsgBox(prompt, buttons, title, helpfile, context) Prompt, the only required argument, is the string of text, surrounded by quotes, that you would like to display in the message box Buttons, (optional), describes the number and type of buttons displayed in the dialog box; determines the icon style; determines which button is the default; and determines the modality (on/off position) of the message box Title, (optional), displayed on the title bar of the message box Helpfile, and Context, (optional), identify which Help file to use to provide contextsensitive Help for the message box. (It is very unusual to use this because the helpfile needs to be constructed and compiled using Microsoft tools not provided with Office 2000). The buttons argument consists of constants or values from each of the following three groups: Number and type of button Constant Value Display VbOKOnly 0 OK button only. vbokcancel 1 OK and Cancel buttons vbabortretryignore 2 Abort, Retry and Ignore buttons vbyesnocancel 3 Yes, No and Cancel buttons VbYesNo 4 Yes and No buttons vbretrycancel 5 Retry and Cancel buttons
50 Lesson 6 Interactive Macros Excel 2000: Level 5 (VBA Programming) Icon style Constant Value Display Icon vbcritical 16 Display Critical Message icon. vbquestion 32 Display Warning Query icon. vbexclamation 48 Display Warning Message icon. vbinformation 64 Display Information Message icon. Default Button Constant Value Default vbdefaultbutton1 0 First button is default vbdefaultbutton1 256 Second button is default vbdefaultbutton1 512 third button is default The value returned by the function depends upon which button was pressed. The value is returned as a constant, which is equal in value to a number. The constant or the value can be tested by the procedure. The constants are specified by Visual Basic Applications: Constant Value Button Selected vbok 1 OK vbcancel 2 Cancel vbabort 3 Abort vbretry 4 Retry vbignore 5 Ignore vbyes 6 Yes vbno 7 No
51 Excel 2000: Level 5 (VBA Programming) Lesson 6 Interactive Macros Procedures 1. Open Workbook. 2. Switch to the Visual Basic Editor. 3. Edit existing Module. 4. Add Msgbox function. 5. Run macro CREATING A CUSTOM INPUT BOX Discussion The InputBox statement displays a prompt in a dialog box prompting the user for data. This data is then stored usually, to a variable. The dialog box has an OK button, a Cancel button and a Help button (although optional). By default the Inputbox dialog box will appear centred on the screen, however this position can be altered. The syntax for the InputBox statement is: InputBox(prompt, title, default, xpos, ypos, helpfile, context) Prompt, the only required argument, is the string of text, surrounded by quotes, that you would like to display in the dialog box. The maximum length is 1024 characters. Title, (optional), represents what is displayed on the title bar of the dialog box. The default title will be Microsoft Excel. Default, (optional), represents a string expression that is displayed in the text box as the default response, if no other input is provided. If you omit the default, the text box is displayed as empty. Xpos, and ypos, (optional), are numeric expressions that specify the horizontal and vertical distances of the edges of the dialog box from the screen. If xpos and ypos are omitted the dialog box is horizontally centred. (It is very unusual to use this, because the exact position varies between types of monitor, even though Excel tries to compensate for this). The measurement unit used is twips. There are 1440 Twips to an Inch.
52 Lesson 6 Interactive Macros Excel 2000: Level 5 (VBA Programming) Helpfile, and context, (optional), identify which Help file to use to provide contextsensitive Help for the dialog box. (It is very unusual to use this, because the helpfile needs to be constructed and compiled using Microsoft tools not provided with Office 2000). The following statement displays the following dialog box. The user s response is stored in a variable called YName. YName = InputBox("Please Enter Your Name") If the user chooses OK or presses enter the InputBox function returns whatever was typed. If the user selects Cancel or presses Escape the InputBox function returns a zero length string.
53 Excel 2000: Level 5 (VBA Programming) Lesson 6 Interactive Macros Procedures 1. Open Workbook. 2. Switch to the Visual Basic Editor. 3. Edit existing Module. 4. Add InputBox function. 5. Run macro
54 Lesson 6 Interactive Macros Excel 2000: Level 5 (VBA Programming) EXERCISE USING THE INPUTBOX FUNCTION Task To assign values to variables. 1. Open Practice Inputbox. 2. Enable the macros. 3. Examine the Salary Worksheet. 4. Switch to the VBE Window. 5. Assign a variable with an Inputbox to prompt for Rate Per Hour. 6. Assign a variable with an Inputbox to prompt for Weekly Hours. 7. Assign a variable with a calculation to hold Rate Per Hour multiplied by Weekly Hours. 8. Place contents of variables in the necessary cells C4, D4, and E4. 9. Save the file as My Practice Inputbox and close the file
55 APPENDIX I - COURSE CONSOLIDATION EXERCISES The purpose of this section is to consolidate on lessons learnt during this course. Number 1: Using If Then Else Statements and Loops Number 2: Using If Statements, Loops, Variables and MSGBOX Function WWP Training Limited Page 55
56 Excel 2000: Level 5 (VBA Programming) COURSE CONSOLIDATION EXERCISES NUMBER 1 USING IF THEN ELSE STATEMENTS AND LOOPS Task To set an If Condition, together with a Do Until Loop. 1. Open Exam. 2. Insert new Module and add relevant code required which will: a) Add text Pass If maths result is over 60. b) Add text Fail If maths result is 60 or less. c) Add text Resit If maths result is blank. 3. Use a Do Until Loop to complete the Outcome in Column C. 4. Save File as MyExam and continue. 5. Create a new macro and add relevant code required which will add Grades dependant on the maths results: a) U for no maths result b) E for any maths result under 30 c) D for any maths result over 45 d) C for any maths result over 60 e) B for any maths result over 75 f) A for any maths result over Use a Case Statement to complete the Outcome in Column D 7. Save File as MyExam and Close
57 COURSE CONSOLIDATION EXERCISES NUMBER 2 USING IF STATEMENTS, LOOPS, VARIABLES AND MSGBOX FUNCTION Task To set an If Condition, Using a Loop, adding variables and displaying a Message Box. 1. Open Check Orders. 2. View the Date Checking worksheet. 3. Insert a new Module and create a new macro which will: a) Look at Column G Orders Required and compare to Column H Orders Sent. b) If the Orders Required is earlier than Orders Sent or orders sent is blank, Then. c) Format the Date in Orders Required to Font Colour of Red. 4. Use a Do Until Loop to Format all the necessary dates to Red in Column G. 5. Save File as My Check Orders and continue. 6. Create a new macro and add relevant code required, which will: a) Look at all dates in Column G. b) Counting each date that is formatted as Font Colour Red and adding the number to a variable. c) Once all dates have been counted. Place the Answer in a Message Box. 7. Save File as My Check Orders and Close
58 INDEX A Adding and Assigning a Custom Button Assigning a Macro to a Menu C Copying a Macro Button Creating a Custom Message Box Creating a Macro Button D Defining Macros... 8 Deleting a Macro Button Deleting a Macro from a Menu Deleting a Personal Macro E Editing a Macro Manually F Formatting a Macro Button G g/sizing a Macro Button M Macro buttons copying creating... 26, 27, 37, 38, 39, 49 deleting formatting moving... 31, 32 sizing... 31, 32 using Macros assigning a shortcut key... 11, 12 assigning to a menu... 13, 14 defining... 8 deleting from a menu...14, 15 deleting personal...20, 21 editing manually...17, 18 recording... 9, 10 recording a personal...18, 19 running...10, 11 using absolute references...15, 16 using relative references...15, 16 viewing the Personal Macro Workbook...19, 20 Msgbox Function O Objects Methods and Properties R Recording a Macro... 9 Recording a Personal Macro Running a Macro T The If Then Control Structure The Select Case Control Structure Toolbars adding a custom button...12, 13 U Using a Do Loop Statement Using a For Each Next Statement Using a For Next Statement Using a Macro Button Using Absolute References V Variable Types Variables and Assignment Statements Viewing the Personal Macro Workbook Page 58 WWP Training Limited
variables programming statements
1 VB PROGRAMMERS GUIDE LESSON 1 File: VbGuideL1.doc Date Started: May 24, 2002 Last Update: Dec 27, 2002 ISBN: 0-9730824-9-6 Version: 0.0 INTRODUCTION TO VB PROGRAMMING VB stands for Visual Basic. Visual
More informationUnderstanding the MsgBox command in Visual Basic
Understanding the MsgBox command in Visual Basic This VB2008 tutorial explains how to use the MsgBox function in Visual Basic. This also works for VBS MsgBox. The MsgBox function displays a message in
More informationExcel & Visual Basic for Applications (VBA)
Class meeting #18 Monday, Oct. 26 th GEEN 1300 Introduction to Engineering Computing Excel & Visual Basic for Applications (VBA) user interfaces o on-sheet buttons o InputBox and MsgBox functions o userforms
More informationMICROSOFT EXCEL VISUAL BASIC FOR APPLICATIONS INTRODUCTION
MICROSOFT EXCEL VISUAL BASIC FOR APPLICATIONS INTRODUCTION Welcome! Thank you for choosing WWP as your learning and development provider. We hope that your programme today will be a stimulating, informative
More informationProgramming Concepts and Skills. Arrays continued and Functions
Programming Concepts and Skills Arrays continued and Functions Fixed-Size vs. Dynamic Arrays A fixed-size array has a limited number of spots you can place information in. Dim strcdrack(0 to 2) As String
More informationMICROSOFT EXCEL VISUAL BASIC FOR APPLICATIONS INTERMEDIATE
MICROSOFT EXCEL VISUAL BASIC FOR APPLICATIONS INTERMEDIATE NOTE Unless otherwise stated, screenshots of dialog boxes and screens in this book were taken using Excel 2003 running on Window XP Professional.
More informationIFA/QFN VBA Tutorial Notes prepared by Keith Wong
Chapter 2: Basic Visual Basic programming 2-1: What is Visual Basic IFA/QFN VBA Tutorial Notes prepared by Keith Wong BASIC is an acronym for Beginner's All-purpose Symbolic Instruction Code. It is a type
More informationVBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide
VBA Visual Basic for Applications Learner Guide 1 Table of Contents SECTION 1 WORKING WITH MACROS...5 WORKING WITH MACROS...6 About Excel macros...6 Opening Excel (using Windows 7 or 10)...6 Recognizing
More informationMicrosoft Excel 2010 Handout
Microsoft Excel 2010 Handout Excel is an electronic spreadsheet program you can use to enter and organize data, and perform a wide variety of number crunching tasks. Excel helps you organize and track
More informationEXCEL 2003 DISCLAIMER:
EXCEL 2003 DISCLAIMER: This reference guide is meant for experienced Microsoft Excel users. It provides a list of quick tips and shortcuts for familiar features. This guide does NOT replace training or
More informationExcel Macro Record and VBA Editor. Presented by Wayne Wilmeth
Excel Macro Record and VBA Editor Presented by Wayne Wilmeth 1 What Is a Macro? Automates Repetitive Tasks Written in Visual Basic for Applications (VBA) Code Macro Recorder VBA Editor (Alt + F11) 2 Executing
More information1 THE PNP BASIC COMPUTER ESSENTIALS e-learning (MS Excel 2007)
1 THE PNP BASIC COMPUTER ESSENTIALS e-learning (MS Excel 2007) 2 THE PNP BASIC COMPUTER ESSENTIALS e-learning (MS Excel 2007) TABLE OF CONTENTS CHAPTER 1: GETTING STARTED... 5 THE EXCEL ENVIRONMENT...
More informationLesson 2. Using the Macro Recorder
Lesson 2. Using the Macro Recorder When the recorder is activated, everything that you do will be recorded as a Macro. When the Macro is run, everything that you recorded will be played back exactly as
More information6/14/2010. VBA program units: Subroutines and Functions. Functions: Examples: Examples:
VBA program units: Subroutines and Functions Subs: a chunk of VBA code that can be executed by running it from Excel, from the VBE, or by being called by another VBA subprogram can be created with the
More informationUsing Microsoft Excel
Using Microsoft Excel Formatting a spreadsheet means changing the way it looks to make it neater and more attractive. Formatting changes can include modifying number styles, text size and colours. Many
More informationIntroduction to macros
L E S S O N 7 Introduction to macros Suggested teaching time 30-40 minutes Lesson objectives To understand the basics of creating Visual Basic for Applications modules in Excel, you will: a b c Run existing
More informationExcel Tutorial 1
IT٢.we Excel 2003 - Tutorial 1 Spreadsheet Basics Screen Layout Title bar Menu bar Standard Toolbar Other Tools Task Pane Adding and Renaming Worksheets Modifying Worksheets Moving Through Cells Adding
More information3 IN THIS CHAPTER. Understanding Program Variables
Understanding Program Variables Your VBA procedures often need to store temporary values for use in statements and calculations that come later in the code. For example, you might want to store values
More informationExcel 2016 Basics for Windows
Excel 2016 Basics for Windows Excel 2016 Basics for Windows Training Objective To learn the tools and features to get started using Excel 2016 more efficiently and effectively. What you can expect to learn
More informationYou can record macros to automate tedious
Introduction to Macros You can record macros to automate tedious and repetitive tasks in Excel without writing programming code directly. Macros are efficiency tools that enable you to perform repetitive
More informationWEEK NO. 12 MICROSOFT EXCEL 2007
WEEK NO. 12 MICROSOFT EXCEL 2007 LESSONS OVERVIEW: GOODBYE CALCULATORS, HELLO SPREADSHEET! 1. The Excel Environment 2. Starting A Workbook 3. Modifying Columns, Rows, & Cells 4. Working with Worksheets
More informationAn InputBox( ) function will display an input Box window where the user can enter a value or a text. The format is
InputBox( ) Function An InputBox( ) function will display an input Box window where the user can enter a value or a text. The format is A = InputBox ( Question or Phrase, Window Title, ) Example1: Integer:
More informationOffice of Instructional Technology
Office of Instructional Technology Microsoft Excel 2016 Contact Information: 718-254-8565 ITEC@citytech.cuny.edu Contents Introduction to Excel 2016... 3 Opening Excel 2016... 3 Office 2016 Ribbon... 3
More informationIT ACADEMY LESSON PLAN
IT Academy Program 10 IT ACADEMY LESSON PLAN Microsoft Excel Lesson 1 Turn potential into success Lesson 1: Understanding Microsoft Office Excel 2010 Learning Objectives Lesson Introduction Creating a
More informationMicrosoft Excel 2002 M O D U L E 2
THE COMPLETE Excel 2002 M O D U L E 2 CompleteVISUAL TM Step-by-step Series Computer Training Manual www.computertrainingmanual.com Copyright Notice Copyright 2002 EBook Publishing. All rights reserved.
More informationMODULE VI: MORE FUNCTIONS
MODULE VI: MORE FUNCTIONS Copyright 2012, National Seminars Training More Functions Using the VLOOKUP and HLOOKUP Functions Lookup functions look up values in a table and return a result based on those
More informationSection 1 Microsoft Excel Overview
Course Topics: I. MS Excel Overview II. Review of Pasting and Editing Formulas III. Formatting Worksheets and Cells IV. Creating Templates V. Moving and Navigating Worksheets VI. Protecting Sheets VII.
More informationGetting started 7. Writing macros 23
Contents 1 2 3 Getting started 7 Introducing Excel VBA 8 Recording a macro 10 Viewing macro code 12 Testing a macro 14 Editing macro code 15 Referencing relatives 16 Saving macros 18 Trusting macros 20
More information12 BASICS OF MS-EXCEL
12 BASICS OF MS-EXCEL 12.1 INTRODUCTION MS-Excel 2000 is a Windows based application package. It is quite useful in entering, editing, analysis and storing of data. Arithmetic operations with numerical
More informationWhen you pass Exam : Access 2010, you complete the requirements for the Microsoft Office Specialist (MOS) - Access 2010 certification.
Appendix 1 Microsoft Office Specialist: Access Certification Introduction The candidates for Microsoft Office Specialist certification should have core-level knowledge of Microsoft Office Access 2010.
More informationMoving and copying data
L E S S O N 4 Moving and copying data Suggested teaching time 50-60 minutes Lesson objectives To be able to move and copy data, you will: a b c d e Insert rows and ranges by using shortcut menu choices.
More informationThe American University in Cairo. Academic Computing Services. Excel prepared by. Maha Amer
The American University in Cairo Excel 2000 prepared by Maha Amer Spring 2001 Table of Contents: Opening the Excel Program Creating, Opening and Saving Excel Worksheets Sheet Structure Formatting Text
More informationMICROSOFT EXCEL. VERSIONS 2007 & 2010 Level 2
MICROSOFT EXCEL VERSIONS 2007 & 2010 Level 2 Welcome! Thank you for choosing WWP as your learning and development provider. We hope that your programme today will be a stimulating, informative and rewarding
More informationExcel 2016 Basics for Mac
Excel 2016 Basics for Mac Excel 2016 Basics for Mac Training Objective To learn the tools and features to get started using Excel 2016 more efficiently and effectively. What you can expect to learn from
More informationMacros in Excel: Recording, Running, and Editing
Macros in Excel: Recording, Running, and Editing This document provides instructions for creating, using, and revising macros in Microsoft Excel. Simple, powerful, and easy to customize, Excel macros can
More informationData Service Center December
www.dataservice.org Data Service Center December 2005 504-7222 Property of the Data Service Center, Wilmington, DE For Use Within the Colonial & Red Clay Consolidated Public School Districts Only Table
More informationLearning Worksheet Fundamentals
1.1 LESSON 1 Learning Worksheet Fundamentals After completing this lesson, you will be able to: Create a workbook. Create a workbook from a template. Understand Microsoft Excel window elements. Select
More informationExcel. module. Lesson 1 Create a Worksheet Lesson 2 Create and Revise. Lesson 3 Edit and Format
module 2 Excel Lesson 1 Create a Worksheet Lesson 2 Create and Revise Formulas Lesson 3 Edit and Format Worksheets Lesson 4 Print Worksheets Lesson 5 Modify Workbooks Lesson 6 Create and Modify Charts
More informationCreate your first workbook
Create your first workbook You've been asked to enter data in Excel, but you've never worked with Excel. Where do you begin? Or perhaps you have worked in Excel a time or two, but you still wonder how
More informationECDL Module 4 REFERENCE MANUAL
ECDL Module 4 REFERENCE MANUAL Spreadsheets Microsoft Excel XP Edition for ECDL Syllabus Four PAGE 2 - ECDL MODULE 4 (USING MICROSOFT EXCEL XP) - MANUAL 4.1 USING THE APPLICATION... 4 4.1.1 FIRST STEPS
More informationMacros enable you to automate almost any task that you can undertake
Chapter 1: Building and Running Macros In This Chapter Understanding how macros do what they do Recording macros for instant playback Using the relative option when recording macros Running the macros
More informationExcel Macros, Links and Other Good Stuff
Excel Macros, Links and Other Good Stuff COPYRIGHT Copyright 2001 by EZ-REF Courseware, Laguna Beach, CA http://www.ezref.com/ All rights reserved. This publication, including the student manual, instructor's
More informationAs you probably know, Microsoft Excel is an
Introducing Excel Programming As you probably know, Microsoft Excel is an electronic worksheet you can use for a variety of purposes, including the following: maintain lists; perform mathematical, financial,
More informationTeach Yourself Microsoft Excel Topic 5: Revision, Headers & Footers, Metadata
Teach Yourself Microsoft Excel Topic 5: Revision, Headers & Footers, Metadata http://www.gerrykruyer.com In this first lesson of this level 2 course you will cover basic Microsoft Excel concepts as well
More informationVBA. VBA at a glance. Lecture 61
VBA VBA at a glance Lecture 61 1 Activating VBA within SOLIDWORKS Lecture 6 2 VBA Sub main() Function Declaration Dim A, B, C, D, E As Double Dim Message, Title, Default Message = "A : " ' Set prompt.
More informationSpreadsheets Microsoft Office Button Ribbon
Getting started with Excel 2007 you will notice that there are many similar features to previous versions. You will also notice that there are many new features that you ll be able to utilize. There are
More informationUsing Microsoft Excel
Using Microsoft Excel Table of Contents The Excel Window... 2 The Formula Bar... 3 Workbook View Buttons... 3 Moving in a Spreadsheet... 3 Entering Data... 3 Creating and Renaming Worksheets... 4 Opening
More informationMicrosoft Excel 2010 Basics
Microsoft Excel 2010 Basics Starting Word 2010 with XP: Click the Start Button, All Programs, Microsoft Office, Microsoft Excel 2010 Starting Word 2010 with 07: Click the Microsoft Office Button with the
More informationExcel 2010 Foundation. Excel 2010 Foundation SAMPLE
Excel 2010 Foundation Excel 2010 Foundation Excel 2010 Foundation Page 2 2010 Cheltenham Courseware Pty. Ltd. All trademarks acknowledged. E&OE. No part of this document may be copied without written permission
More informationExcel Main Screen. Fundamental Concepts. General Keyboard Shortcuts Open a workbook Create New Save Preview and Print Close a Workbook
Excel 2016 Main Screen Fundamental Concepts General Keyboard Shortcuts Open a workbook Create New Save Preview and Print Close a Ctrl + O Ctrl + N Ctrl + S Ctrl + P Ctrl + W Help Run Spell Check Calculate
More informationGloucester County Library System EXCEL 2007
Gloucester County Library System EXCEL 2007 Introduction What is Excel? Microsoft E x c e l is an electronic s preadsheet program. I t is capable o f performing many diff e r e n t t y p e s o f c a l
More informationCreating a Spreadsheet by Using Excel
The Excel window...40 Viewing worksheets...41 Entering data...41 Change the cell data format...42 Select cells...42 Move or copy cells...43 Delete or clear cells...43 Enter a series...44 Find or replace
More informationCorel Ventura 8 Introduction
Corel Ventura 8 Introduction Training Manual A! ANZAI 1998 Anzai! Inc. Corel Ventura 8 Introduction Table of Contents Section 1, Introduction...1 What Is Corel Ventura?...2 Course Objectives...3 How to
More informationAdvanced Excel Macros : Data Validation/Analysis : OneDrive
Advanced Excel Macros : Data Validation/Analysis : OneDrive Macros Macros in Excel are in short, a recording of keystrokes. Beyond simple recording, you can use macros to automate tasks that you will use
More informationIntroduction to Microsoft Excel 2010
Introduction to Microsoft Excel 2010 THE BASICS PAGE 02! What is Microsoft Excel?! Important Microsoft Excel Terms! Opening Microsoft Excel 2010! The Title Bar! Page View, Zoom, and Sheets MENUS...PAGE
More informationMicrosoft Excel 2010 Part 2: Intermediate Excel
CALIFORNIA STATE UNIVERSITY, LOS ANGELES INFORMATION TECHNOLOGY SERVICES Microsoft Excel 2010 Part 2: Intermediate Excel Spring 2014, Version 1.0 Table of Contents Introduction...3 Working with Rows and
More informationEXCEL BASICS: MICROSOFT OFFICE 2007
EXCEL BASICS: MICROSOFT OFFICE 2007 GETTING STARTED PAGE 02 Prerequisites What You Will Learn USING MICROSOFT EXCEL PAGE 03 Opening Microsoft Excel Microsoft Excel Features Keyboard Review Pointer Shapes
More informationApplication of Skills: Microsoft Excel 2013 Tutorial
Application of Skills: Microsoft Excel 2013 Tutorial Throughout this module, you will progress through a series of steps to create a spreadsheet for sales of a club or organization. You will continue to
More informationExcel Select a template category in the Office.com Templates section. 5. Click the Download button.
Microsoft QUICK Excel 2010 Source Getting Started The Excel Window u v w z Creating a New Blank Workbook 2. Select New in the left pane. 3. Select the Blank workbook template in the Available Templates
More informationBudget Exercise for Intermediate Excel
Budget Exercise for Intermediate Excel Follow the directions below to create a 12 month budget exercise. Read through each individual direction before performing it, like you are following recipe instructions.
More informationOpen Office Calc (Spreadsheet) Tutorial
Open Office Calc (Spreadsheet) Tutorial Table of Contents Introduction...3 What is a Spreadsheet?...3 Starting OpenOffice Calc...3 OpenOffice Calc (Spreadsheet) Basics...4 Creating a New Document...5 Entering
More informationTeacher s Guide. PCIC 3 B2 GS3- Key Applications-Excel. Text of Frequently Asked Questions. Copyright 2010 Teknimedia Corporation
Teacher s Guide - Key Applications-Excel Text of Frequently Asked Questions Copyright 2010 Teknimedia grants permission to any licensed owner of Key Applications-Excel to duplicate the contents of this
More informationMicrosoft Excel 2010 Level 1
Microsoft Excel 2010 Level 1 One Day Course Course Description You have basic computer skills such as using a mouse, navigating through windows, and surfing the Internet. You have also used paper-based
More informationMacros enable you to automate almost any task that you can undertake
Chapter 1: Building and Running Macros In This Chapter Understanding how macros do what they do Recording macros for instant playback Using the relative option when recording macros Running the macros
More informationIntroduction to Microsoft Excel 2016
Screen Elements: Introduction to Microsoft Excel 2016 The Ribbon The Ribbon is designed to help you quickly find the commands that you need to complete a task. Commands are organized in logical groups,
More informationLes s on Objectives. Student Files Us ed
Lesson 3 - Potpourri 31 Lesson 3 P otpourri Les s on Topics The Fill Command Wrapping Text View Options Edit Options Other Fill Handle Uses Les s on Objectives At the end of the lesson, you will be able
More informationMS Excel Henrico County Public Library. I. Tour of the Excel Window
MS Excel 2013 I. Tour of the Excel Window Start Excel by double-clicking on the Excel icon on the desktop. Excel may also be opened by clicking on the Start button>all Programs>Microsoft Office>Excel.
More information13 FORMATTING WORKSHEETS
13 FORMATTING WORKSHEETS 13.1 INTRODUCTION Excel has a number of formatting options to give your worksheets a polished look. You can change the size, colour and angle of fonts, add colour to the borders
More informationExcel Pivot Tables & Macros
Excel 2007 Pivot Tables & Macros WORKSHOP DESCRIPTION...1 Overview 1 Prerequisites 1 Objectives 1 WHAT IS A PIVOT TABLE...2 Sample Example 2 PivotTable Terminology 3 Creating a PivotTable 4 Layout of
More information1: Getting Started with Microsoft Excel
1: Getting Started with Microsoft Excel The Workspace 1 Menu commands 2 Toolbars 3 Cell References 4 Cell Entries 4 Formatting 5 Saving and Opening Workbook Files 7 The Workspace Figure 1 shows the Microsoft
More informationStatus Bar: Right click on the Status Bar to add or remove features.
Excel 2013 Quick Start Guide The Excel Window File Tab: Click to access actions like Print, Save As, etc. Also to set Excel options. Ribbon: Logically organizes actions onto Tabs, Groups, and Buttons to
More informationMicrosoft Excel for Lawyers - The Fundamentals Reference Guide
Microsoft Excel for Lawyers - The Fundamentals Reference Guide This guide includes step by step procedures for fundamental Excel commands and accompanies the Microsoft Excel for Lawyers -The Fundamentals
More informationEXCEL BASICS: MICROSOFT OFFICE 2010
EXCEL BASICS: MICROSOFT OFFICE 2010 GETTING STARTED PAGE 02 Prerequisites What You Will Learn USING MICROSOFT EXCEL PAGE 03 Opening Microsoft Excel Microsoft Excel Features Keyboard Review Pointer Shapes
More informationUsing Microsoft Excel
Using Microsoft Excel Excel contains numerous tools that are intended to meet a wide range of requirements. Some of the more specialised tools are useful to people in certain situations while others have
More informationMicrosoft Excel XP. Intermediate
Microsoft Excel XP Intermediate Jonathan Thomas March 2006 Contents Lesson 1: Headers and Footers...1 Lesson 2: Inserting, Viewing and Deleting Cell Comments...2 Options...2 Lesson 3: Printing Comments...3
More informationAdvanced Excel. Click Computer if required, then click Browse.
Advanced Excel 1. Using the Application 1.1. Working with spreadsheets 1.1.1 Open a spreadsheet application. Click the Start button. Select All Programs. Click Microsoft Excel 2013. 1.1.1 Close a spreadsheet
More informationCheck the spelling of the worksheet by using Excel s spelling check feature.
L E S S O N 6 Printing a worksheet Suggested teaching time 40-50 minutes Lesson objectives To prepare a worksheet for printing, you will: a b c d Check the spelling of the worksheet by using Excel s spelling
More informationSkills Exam Objective Objective Number
Overview 1 LESSON SKILL MATRIX Skills Exam Objective Objective Number Starting Excel Create a workbook. 1.1.1 Working in the Excel Window Customize the Quick Access Toolbar. 1.4.3 Changing Workbook and
More informationUsing Basic Formulas 4
Using Basic Formulas 4 LESSON SKILL MATRIX Skills Exam Objective Objective Number Understanding and Displaying Formulas Display formulas. 1.4.8 Using Cell References in Formulas Insert references. 4.1.1
More informationWorkbook Also called a spreadsheet, the Workbook is a unique file created by Excel. Title bar
Microsoft Excel 2007 is a spreadsheet application in the Microsoft Office Suite. A spreadsheet is an accounting program for the computer. Spreadsheets are primarily used to work with numbers and text.
More informationUsing Microsoft Excel
Using Microsoft Excel Excel contains numerous tools that are intended to meet a wide range of requirements. Some of the more specialised tools are useful to only certain types of people while others have
More information6. Essential Spreadsheet Operations
6. Essential Spreadsheet Operations 6.1 Working with Worksheets When you open a new workbook in Excel, the workbook has a designated number of worksheets in it. You can specify how many sheets each new
More informationExcel Simple Worksheets (with Functions)
Excel 2007 Simple Worksheets (with Functions) Contents The Excel 2007 Window 4 Navigating in Excel... 7 Entering Data 8 Working with Ranges of Cells... 9 Selecting Ranges of Cells 9 Copy and Moving Cell
More informationIntroduction to Excel 2007 Table of Contents
Table of Contents Excel Microsoft s Spreadsheet... 1 Starting Excel... 1 Excel 2007 New Interface... 1 Exploring the Excel Screen... 2 Viewing Dialog Boxes... 2 Quick Access Toolbar... 3 Minimizing the
More informationIntroduction to Excel
Office Button, Tabs and Ribbons Office Button The File menu selection located in the upper left corner in previous versions of Excel has been replaced with the Office Button in Excel 2007. Clicking on
More informationIntroduction to Excel 2013
Introduction to Excel 2013 Copyright 2014, Software Application Training, West Chester University. A member of the Pennsylvania State Systems of Higher Education. No portion of this document may be reproduced
More informationMicrosoft Excel 2007 Macros and VBA
Microsoft Excel 2007 Macros and VBA With the introduction of Excel 2007 Microsoft made a number of changes to the way macros and VBA are approached. This document outlines these special features of Excel
More informationPART 7. Getting Started with Excel
PART 7 Getting ed with Excel When you start the application, Excel displays a blank workbook. A workbook is a file in which you store your data, similar to a three-ring binder. Within a workbook are worksheets,
More informationMicrosoft Word Part I Reference Manual
Microsoft Word 2002 Part I Reference Manual Instructor: Angela Sanderson Computer Training Coordinator Updated by: Angela Sanderson January 11, 2003 Prepared by: Vi Johnson November 20, 2002 THE WORD SCREEN
More informationExcel Advanced
Excel 2016 - Advanced LINDA MUCHOW Alexandria Technical & Community College 320-762-4539 lindac@alextech.edu Table of Contents Macros... 2 Adding the Developer Tab in Excel 2016... 2 Excel Macro Recorder...
More informationMicrosoft Excel Chapter 1. Creating a Worksheet and a Chart
Microsoft Excel 2013 Chapter 1 Creating a Worksheet and a Chart Objectives Describe the Excel worksheet Enter text and numbers Use the Sum button to sum a range of cells Enter a simple function Copy the
More informationMICROSOFT EXCEL VISUAL BASIC FOR APPLICATIONS INTRODUCTION
MICROSOFT EXCEL VISUAL BASIC FOR APPLICATIONS INTRODUCTION NOTE Unless otherwise stated, screenshots of dialog boxes and screens in this book were taken using Excel 2003 running on Window XP Professional.
More informationMODULE III: NAVIGATING AND FORMULAS
MODULE III: NAVIGATING AND FORMULAS Copyright 2012, National Seminars Training Navigating and Formulas Using Grouped Worksheets When multiple worksheets are selected, the worksheets are grouped. If you
More informationSection 8 Formatting
Section 8 Formatting By the end of this Section you should be able to: Format Numbers, Dates & Percentages Change Cell Alignment and Rotate Text Add Borders and Colour Change Row Height and Column Width
More informationExcel Expert Microsoft Excel 2010
Excel Expert Microsoft Excel 2010 Formulas & Functions Table of Contents Excel 2010 Formulas & Functions... 2 o Formula Basics... 2 o Order of Operation... 2 Conditional Formatting... 2 Cell Styles...
More informationMS Excel Henrico County Public Library. I. Tour of the Excel Window
MS Excel 2013 I. Tour of the Excel Window Start Excel by double-clicking on the Excel icon on the desktop. Excel may also be opened by clicking on the Start button>all Programs>Microsoft Office>Excel.
More informationUsing Microsoft Excel
About Excel Using Microsoft Excel What is a Spreadsheet? Microsoft Excel is a program that s used for creating spreadsheets. So what is a spreadsheet? Before personal computers were common, spreadsheet
More informationMicrosoft Office Excel 2007: Basic. Course Overview. Course Length: 1 Day. Course Overview
Microsoft Office Excel 2007: Basic Course Length: 1 Day Course Overview This course teaches the basic functions and features of Excel 2007. After an introduction to spreadsheet terminology and Excel's
More informationIntroduction to Microsoft Word 2010
Introduction to Microsoft Word 2010 Microsoft Word is a word processing program you can use to write letters, resumes, reports, and more. Anything you can create with a typewriter, you can create with
More informationWord - Basics. Course Description. Getting Started. Objectives. Editing a Document. Proofing a Document. Formatting Characters. Formatting Paragraphs
Course Description Word - Basics Word is a powerful word processing software package that will increase the productivity of any individual or corporation. It is ranked as one of the best word processors.
More information