Chapter 2. Getting Started with Macros

In Lesson 1, you read that VBA is the programming language of Microsoft Excel and that a macro is a sequence of VBA commands to run a task automatically instead of manually. In this lesson, you learn how to create a simple macro, what its code looks like, and a few options for how you can run the macro.


This lesson leads you through the process of composing a macro to sort and format a range of data. But even before the first line of programming code is written, you'll want to set up shop by giving yourself easy access to the VBA-related tools you'll be using. The following housekeeping tips usually need to be done only once, and are worth taking the time to do now, if you haven't already done so.

Accessing the VBA Environment

At the time of this writing, Excel is at a unique stage in its ongoing evolution, because three of its versions are being used with substantial popularity. Version 2003 (also known as version 11) was the final Excel version having the traditional menu bar interface of File, Edit, View, and so on. Then came version 2007 (also known as version 12) with Office's new Ribbon interface, and most recently, version 2010 (also known as version 14) has taken its place among the community of Excel users.

As with other tasks you typically do in Excel, the actions you take to create, view, edit, or run VBA code usually start by clicking the on-screen icon relating to that task. Exactly what those VBA-related ...

Get Excel® VBA: 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.