Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spreadsheets in Finance and Forecasting Presentation 9 Macros.

Similar presentations


Presentation on theme: "Spreadsheets in Finance and Forecasting Presentation 9 Macros."— Presentation transcript:

1 Spreadsheets in Finance and Forecasting Presentation 9 Macros

2 Objectives After studying this week’s material you will be able to: Use macros to automate formatting and printing Add controls to your worksheets which will enable users to : Switch between pages Update sections of a database Add selected charts to illustrate tables.

3 Using this Presentation The presentation is broken down into an Introduction and 5 separate sections. You should work through these in order, making sure that you have completed all the tasks in one section before going on to the next. A spreadsheet called Macro Examples accompanies this presentation. When you have finished all the sections in this presentation, you should go on to Formative Activity 7.

4 Introduction What are Macros? How do we create them?

5 What is a Macro? A macro is a piece of Visual Basic Code which executes a task or series of tasks. Macros are usually “recordings” of actions performed by the user.

6 What are Macros for? Macros are used to save time and effort. For example if you always format your tables in a particular way, you can use a macro to do this for you to save you pressing lots of buttons and remembering how you did it last time.

7 How do Macros work? We “record” Macros, in the same way that you would record an event with a video- recorder. You set press a “record” button, and Excel records all your actions. Later on you can “play back” the actions you recorded.

8 The Macro Examples Spreadsheet The spreadsheet Macro Examples accompanies this presentation. During this presentation we will develop examples of Macros to carry out the tasks in the following areas: 1. Printing 2. Formatting 3. Page Switching and Selection 4. Sorting 5. Worksheet Options

9 Macro Examples The spreadsheet Macro Examples will be used to develop some of the ideas. Load this spreadsheet now, so that you can do the activities. Action Point

10 Macro Toolbar Settings Before you do any work with macros you need to ensure that you have Excel configured correctly Click on View – Toolbars and Select the Visual Basic Toolbar TheVisual Basic Toolbar appears up here Action Point

11 Recording Macros The sequence for Recording Macros is: 1. START RECORDING: Click on the Blue Dot (Macro Toolbar) Name the Macro 2. RECORD ACTIONS: Carry out the Action you wish to record 3. STOP RECORDING: Click on the Blue Square (Macro Toolbar)

12 Testing, Testing … Just to test that your toolbar is working, try the following: Click on the Blue Square In the dialogue box, write Testing Click on OK Click on the Blue Circle Action Point NB. You may find that a separate little toolbar appears, with a Blue STOP square on it. If you have this, then you can use this instead of the button on the Macro toolbar. NB. You may find that a separate little toolbar appears, with a Blue STOP square on it. If you have this, then you can use this instead of the button on the Macro toolbar.

13 … Testing To see if your macro has recorded, click on Tools Macro Macros This dialogue box shows you that you have successfully recorded a macro called Testing Action Point

14 There’s nothing in it… If you have got this far, then you have successfully created your first macro. Unfortunately, it’s empty. We did not put any actions in it, so it doesn’t do anything. However, during the next section we will create a macro to carry out useful tasks.

15 Section 1 Macros for Printing

16 We will develop Macros to : Print out a selection Print out in Portrait form Print out in Landscape form

17 Examples: Printing The page is a set of tables documenting the number of student enquiries at the registry counter over a 4 week period. The first Macro we will produce will simply print out a single week’s table First of all, select the table for week 1 using the mouse. Action Point

18 Recording a Macro To record the macro, use the blue button on the Macro Toolbar Alternatively, Click on Tools Macro Record New Macro Action Point

19 Macro Recorder This Dialog Box appears. Change the Macro Name to PrintWeek Click on OK Action Point

20 Recording the PrintWeek Macro The Macro Recorder button should appear here or in the toolbar. This means that every action that you do from now on is being recorded.

21 The Print Dialog Box Click on File – Print The Dialog box (left) appears. We will print the selection. When you press OK, the printing will take place. Action Point

22 The PrintWeek Macro Now click on the The square blue Macro Recorder button. The recording has now stopped, and PrintWeek is now a Macro, and is now a new Excel command. Action Point

23 Running the Macro Highlight the Week 2 table with your cursor, and then: Select Tools- Macro- Macros The dialog box right shows that you have recorded the Macro. Select this macro, then click on Run. This will print out the table you have selected. Action Point

24 Assigning the Macro to a Button Bring the Forms toolbar onto the screen. (View- Toolbars- Forms) From the Forms toolbar, select a Button, and put it on the page at around H25-26. This dialog box appears. Assign the Macro PrintWeek to the button by selecting it. Click OK Action Point

25 Renaming the Button Right click on the button and Edit Text. Rename the Button Print Selection. Action Point

26 Printing another section Now highlight Week 4, and press the button. This time week 4’s text is printed. Action Point

27 Another print button Highlight Week 1 and Week 2. Select Tools- Macro-Record New Macro Name the Macro PrintPortrait Click on OK Action Point

28 PrintPortrait Macro Click on File- Page Setup Select Fit to 1 page wide by 1 page tall Click on OK Action Point

29 PrintPortrait Macro Now Click on File- Print Select Selection Click on OK Then click on the Blue Button on the Macro Recorder to turn it off. Action Point

30 Finishing Off Attach the Macro PrintPortrait to a button. Call this “Portrait”. Check that it works by selecting weeks 3 and 4, and printing off. Action Point

31 Printing Challenge Create a button called “Landscape” which runs a Macro PrintLandscape that prints the selected area in Landscape form. Action Point

32 Section 2 Macros for Formatting

33 We will create a macro which uses an on-screen template as a model for the formatting of a number of similar tables.

34 Formatting Switch the Page to Formatting, and move the cursor over to the right, at around column Q Select and highlight the block of cells Q4 : V12 Action Point

35 Using Auto Format Click on Format – Auto format, and this menu box appears. Scroll down through the examples until you find this one: Click on OK Action Point

36 The Formatted Text This is the result of the Auto- formatting of the text you selected. Now scroll the cursor left and position it at cell H2. Action Point

37 The Formatting Macro Click on Tools-Macro- Record New Macro Call the new Macro FormatWeeks Start Recording Move the cursor to the right and highlight cells Q4:V12 Copy this block of cells Action Point

38 Formatting the tables Position the cursor over cell B4 and click on Edit-Paste Special – Formats Click OK Repeat this at cells B15, I4 and I15. Now click on cell H2 Stop Recording Action Point

39 Adding a Button Add a button at around cell H6 Assign the Macro FormatWeeks that you have just recorded. Call the Button Format Action Point

40 Trying a different Format Now move over to cells Q4 to V12, and experiment with a different format. You could try one of the auto formats, devise your own or modify an auto format like this one: Action Point

41 Formatting all the tables Clicking on the button will now transfer your formatting over to all the tables Action Point

42 Section 3 Macros for Page Selection

43 Page Selection We will create macros that will Switch back and forth between two pages Select pages in a workbook from a Menu

44 Switching Pages Examine Page 1 and Page 2 of the Macro Examples Spreadsheet. On Page 1, record a Macro “Page2” which turns to Page 2. Create a button on Page 1 called “Page 2”, which, when you press it takes you to Page 2. Action Point

45 Switching Pages On Page 2 of the Examples Spreadsheet, create a button called “Page 1”, which, when you press it takes you to Page 1. Action Point

46 Options On the Page Selection sheet, there are two option buttons. Right Click on each of these in turn to attach the appropriate Macro Code so that they do exactly what it says on the label! Action Point

47 Section 4 Macros to Sort Data

48 Sorting We will create Macros to sort a table on a particular row or column.

49 Sorting Macros Switch to the page called Sorting. Record a Macro called Sort 1 Highlight the table as shown here, cells C4 to G10 Action Point

50 Sorting Macros Now click on Data and Sort. Select Options and when the second dialogue box appears, select click on Left to Right. Click Ok, and in the first box, select Row 5. Click on OK to finish. Now stop recording. Action Point

51 The Sorting Buttons Add 6 separate buttons to the spreadsheet which will be assigned to macros Sort1, Sort2 etc., and which sort the table according to each of the rows. Create These Action Point

52 Section 5 Macros to change the look of the Worksheet

53 Worksheet Options The final two macros will change the look of the worksheet itself.

54 Two More Macros On the final page called Blank Page, create two macros which: 1.Removes Gridlines 2.Removes the Border Frame You will need to select Tools-Options, which brings this menu up. Action Point

55 The Final Two Macros Finally add two buttons which switch on the number frame and the gridlines. Action Point

56 The Next Steps Formative Activity 10 takes you through more examples of how macros can be used These will be developed using the spreadsheet Cornershop Revisited Macros include: Updating a database Switching within a sheet Creating Charts


Download ppt "Spreadsheets in Finance and Forecasting Presentation 9 Macros."

Similar presentations


Ads by Google