Appendix 4. Learning VBA Basics for PivotTables

Record a Macro

You can save time and make the process of creating a macro easier by recording some or all the actions you want your macro to perform.

A macro is a sequence of actions, commands, and statements that are executed one after another to perform a specific task. In Excel, as in all the other Office programs that support macros, the macro programming language is called Visual Basic for Applications, or VBA.

VBA is a powerful language that can perform a wide variety of tasks. However, VBA's main task is to operate on the application in which it is running. With Excel VBA, for example, you can create macros that add text and formulas to cells, format ranges, insert or delete worksheets, create and manipulate PivotTables, and much more.

Unfortunately, it can sometimes take a while to build and test a macro, and it is often difficult to remember the objects, properties, and methods that you are required to use to perform a task. Fortunately, when you want to build a macro that manipulates Excel in some way, VBA gives you an alternative method that is faster and easier: the macro recorder. After you activate this tool, you only need to use Excel to perform the action or actions that you want in the macro. All the text or formulas you insert in cells, all the formatting you apply, all the commands and buttons that you click, are recorded, translated into the equivalent VBA statements, and then stored as a macro for later use. You can ...

Get Excel® 2007 PivotTables and PivotCharts now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.