130 likes | 338 Views
Excel Macro VBA Overview. Kevin Fujinami 4/26/2013. What are Excel Macros?. S tep-by-step procedures written in Visual Basic Making code Recording macros Writing code from scratch. Components of VBA Code. Option Explicit Sub UnhideSheets () ‘ Declaring a variable Dim i As Long
E N D
Excel Macro VBA Overview Kevin Fujinami 4/26/2013
What are Excel Macros? • Step-by-step procedures written in Visual Basic • Making code • Recording macros • Writing code from scratch
Components of VBA Code Option Explicit Sub UnhideSheets() ‘ Declaring a variable Dim i As Long ‘ Loop that makes each worksheet visible For i = 1 To Worksheets.Count Worksheets(i).Visible = True Next i End Sub
Setting up Excel for VBA • Developer button in ribbon • Saving files as .xlsm instead of .xlsx • Security
Writing a macro from scratch • Coloring cells based on value • Unhidingworksheets • Pivot table macro
Running Macros • Run from VBA window • Select worksheet before running • Adding a button to Excel Menu
Troubleshoot VBA coding • F8 – Stepping through code • Add watch to view value of variables • Beeps • Start/End time stamps
Code Snippets • Option Explicit • Find last row in table • Make copy of worksheet then run VBA on that copy • Speeding up macro by turning off screen update • Time Stamps • Beeping when done
Tips for becoming proficient • Learn basic programming fundamentals • Read books to discover what Excel VBA functions are available • Google for answers • Write tests for quality assurance • Comment your code
Resources • Books • VBA and Macros: Microsoft Excel 2010 (MrExcel Library) ISBN-13: 978-0789743145 • Online resources • http://www.mrexcel.com/ • http://ozgrid.com • http://msdn.microsoft.com/en-us/library/office/ee814737(v=office.14).aspx