Microsoft Office Tutorials and References
In Depth Information
Understanding the Code
If you are using Excel version 2007 or 2010, your recorded code will look a
bit different from the 2003 version code. However, this macro produced by the
Macro Recorder in version 2003 will work just fine in those later versions.
understanding the code
All macros start with a Sub statement (Sub is short for Subroutine, commonly referred to as a
macro) that includes the name of the macro, followed by a pair of parentheses. Here, the Sub
statement is simply Sub mySort() .
Because this macro was recorded, there is a series of comment lines below the Sub statement that
the Macro Recorder wants you to know about. For example, you see the macro name, the
description of the macro you entered into the Record Macro dialog box, and the notation that the shortcut
Ctrl+Shift+S has been assigned to this macro.
Comment lines start with an apostrophe, are green in color to help you identify them, and are not
executed as VBA code, as opposed to the other lines of VBA code that actually do something when
the macro is running.
The remaining lines in the macro are VBA statements, and they represent every action that was
taken while the Macro Recorder was on:
The first thing you did was select column A.
Next, you inserted a new column at column A.
Next, you selected column C, cut that column, and pasted it to column A.