Macro Recorder Code Cleanup

Refer to the part one file for the beginning of the lesson.

Index Builder Exercise

Index Builder Result

We created the code to select the First sheet.  Before we copy the code, let's trim it down.  To get to the code, select, Tools, Macro, Macros, then highlight, SelectFirst, and then click Edit.

Now trim the code from:

Sub SelectFirst()
'
' SelectFirst Macro
' Macro recorded 2/9/2003 by Jon Paul
'

'
    Sheets("First").Select
End Sub

To:

Sub SelectFirst()
    Sheets("First").Select
End Sub

Since it is a small procedure (the name used to describe an individual program), the comment code automatically recorded by the Excel macro recorder is overkill.

Now let's build the code to select the other two sheets:

You have now created your second procedure, which should look like this:

Sub SelectSecond()
    Sheets("Second").Select
End Sub

Repeat the process to create the code to select the Third sheet.

Let's go over the code section of the procedure.  It has two parts:

Now you have created the code for selecting each individual sheet.

Next we will show how to build the table of contents to complete the task

 

Return To Excel Tips Index