Download presentation
Presentation is loading. Please wait.
Published byCassandra Short Modified over 9 years ago
1
11. Visual Basic Macro Recorder
2
Open Excel
3
Click File -> Save As
4
Save As a Excel Macro-Enabled Workbook
5
Click File -> Options
6
Click Customize Ribbon
7
Tick Developer
8
Click OK
9
Select Developer menu
10
Macro Recorder A job may require you to do the same repetitive task every day in Excel You can make Excel complete some of these tasks automatically by recording a macro All you have to do to repeat the action is to click a button
11
Formatting Cells If you are creating tables of results you may need to format them in a particular way e.g. font, border, background Rather than doing each step repeatedly we can record the actions once, and then make Excel repeat them
12
Type in this table of information
13
Highlight these cells
14
Click Record Macro
15
Macro name: Format Table Shortcut key: Ctrl+o
16
Click OK
17
Every action we take from now on will be recorded until we click Stop Recording
18
Right-click with mouse and select Format Cells
19
Click Font and select Times New Roman, Bold, Size 14 and Colour Dark Blue
20
Click Border and then the Double Lines
21
Select Top and Bottom borders
22
Click OK
23
Click Stop Recording
24
Click Visual Basic
25
Select Module 1
26
Excel has recorded all of the tasks which you have just completed, and written a program
27
You can make changes to this program by typing into the script
28
Click Close
29
Type in the following table
30
Highlight the new table
31
Press Ctrl + o This is the shortcut key we assigned to our macro
32
The macro is run and all of the tasks are completed automatically
33
Challenge Go into Visual Basic editor Change the Font Name to “Verdana” Change the Font Style to “Italic” Change the Font Size to 12 Save and Close the Visual Basic editor Select the table again and press Ctrl+o to reformat the table
34
Trial and Error The best way to learn specific commands in Visual Basic is to use the Macro Recorder You can look at the code that is generated and then try to make some changes
35
Stock Screener By using some creativity you can create complex programs using Visual Basic In the following example we will download data from Yahoo Finance, and then filter it to find companies with a low P/E ratio
36
Select Sheet 2
37
Click Record Macro
38
TypeMacro name: StockScreener Shortcut key: Ctrl + l
39
Click OK
40
Click Data -> Import From Text
41
Type in the following web address http://finance.yahoo.com/d/quotes.csv?s=MSFT+GOOG&f=snpryv
42
Click Open
43
Click Cancel if any passwords are requested
44
Click Next
45
The original data is separated by commas so tick Comma
46
Click Next
47
Click Finish
48
Click OK
49
Click Cancel if any password is requested
50
Imports the data which we asked for
51
Select cell A1
52
Select Insert -> Insert Sheet Rows
53
Type in the following headings
54
Select Column D
55
Click Data -> Filter
56
Click on Dropdown box, then Number Filters -> Less Than …
57
Choose PE less than 20 and click OK
58
Filters data to show companies with a P/E less than 20
59
Click Developer -> Stop Recording
60
Click Visual Basic
61
View the code for the stock screener
62
We can edit which companies we want to download by changing the ticker symbols
63
Replace MSFT+GOOG with AXP+DIS+GE+KO+MCD+PFE
64
Click Save and Close
65
Select Sheet 3
66
Press Ctrl+l to run macro with new companies
67
Shows which companies have a P/E under 20
68
Challenge Create a new sheet Edit the Visual Basic code to download information for the following tickers: – INTC – JNJ – JPM – KO – XOM Change the filter criteria to select companies with a dividend yield less than 3
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.