How do i make a macro?

advertisement
Bullet-Proofing your Excel
Spreadsheets
Tech Day 2013 Presentation
Margaret Gill
mjgill@noctrl.edu
Chris Kardaras
cjkardaras@noctrl.edu
Marco V. Martinez
mvmartinez@noctrl.edu
•
•
•
•
•
•
•
Overview
Data Protection
Why Use Macros?
Enabling Macros, and a Warning
Recording a Macro
Capturing a Formula in a Macro
Resources
Tech Day 11/2013
2
• Data errors can occur in many ways:
– manual entry
– data from external sources
– data transmission errors
• We can make better decisions if we can detect
and prevent invalid data
• In Excel, this is called Data Validation
Tech Day 12/2013
3
Select the cells/rows/columns that you
want to validate, then
Tech Day 12/2013
4
Tech Day 12/2013
5
• Manipulate data
• Apply style and formatting
Tech Day 12/2013
6
• Manipulating research data
Tech Day 11/2013
7
• Classroom gradebook
Tech Day 12/2013
8
Tech Day 12/2013
9
• To execute or work with macros, you must
enable the Developer tab:
, then
Tech Day 12/2013
10
• Most Excel installations have macro execution
disabled by default
• Be careful if you enable macro execution – you
are allowing code to run on your computer
Tech Day 12/2013
11
• Open sample excel file
Tech Day 11/2013
12
• Click on the “Developer” tab
or
Tech Day 12/2013
13
• Do you need your macro to be dependent
upon coordinates, or relative?
– Dependent upon coordinates – only works in
coordinates recorded
– Relative – dependent upon where cursor is
Dependent on coordinates
Tech Day 12/2013
Relative Reference
14
• If want relative reference click “Relative
Reference”
• Click “Record”
Tech Day 12/2013
15
Name your Macro
Click “OK”
Create shortcut
for macro
Tech Day 12/2013
16
Tech Day 12/2013
17
• Click “Stop” when finished
Tech Day 12/2013
18
• When open Excel click either
– “Macros”
– Macros command
“Run”
• (eg. Option + Command + A)
Tech Day 12/2013
19
Tech Day 11/2013
20
Tech Day 11/2013
21
Tech Day 11/2013
22
Tech Day 11/2013
23
Tech Day 11/2013
24
Tech Day 11/2013
25
Tech Day 11/2013
26
Function Area(Length As Double, Width As Double)
Area = Length * Width
End Function
Tech Day 11/2013
27
• Tips on Data Validation
– http://office.microsoft.com/en-us/excel-help/applydata-validation-to-cells-HP010072600.aspx
• Microsoft Excel Recording Macros
– http://office.microsoft.com/en-us/excelhelp/overview-RZ102337714.aspx?CTT=1&section=1
• Excel for Dummies
– http://www.dummies.com/how-to/computerssoftware/ms-office/Excel/Excel-2013/MacrosProgramming.html
Tech Day 12/2013
28
• Writing Your First VBA Function in Excel
– http://www.fontstuff.com/vba/vbatut01.htm
• Writing Your Own Functions In VBA
– http://www.cpearson.com/excel/writingfunctionsi
nvba.aspx
Tech Day 11/2013
29
Download