Microsoft Office Tutorials and References
In Depth Information
Weapons of Mass Debugging
figurE 17-9
Using the Step Into Command
To examine line by line where the problem lies, click your mouse anywhere inside the macro and
then click the Step Into button. The macro’s Sub line will be highlighted in yellow, indicating to you
that it’s that particular macro you are about to step into.
When you “step into” a macro, you are traversing step-by-step (code line by
code line), in a single-step process to execute each line in turn.
Click the Step Into button again and the first line of code will be highlighted in yellow, which in
this example is Range(“A1”).Value = “XYZ Widgets, Inc.” as shown in Figure 17-10. If you
click the Step Into button again, the code line Range(“A1”).Value = “XYZ Widgets, Inc.” will
be executed, and the next line of code, Range(“A2”).Value = “Quarterly Report” , will be
highlighted in yellow, ready to be executed with your next Step Into command.
Each time you click the Step Into button, the line of code that is highlighted will be executed,
and the next line will be highlighted, and so on until you reach the end of the macro. Because
you suspect a bug somewhere in the code, you’d be looking at your worksheet after each Step
Into command to make sure that what the code is supposed to be doing is what it truly is doing.
In this example, all the cell values and formatting were correctly executed when you stepped into
each one, until the very last section of code that executes the Sort method. You find when
stepping into that section that the range of cells being sorted is not correct. Your table occupies range
B4:E14 but the VBA code is sorting only up to row 13. Your suspicions were correct about the
final result on the worksheet looking peculiar, so a quick adjustment is made to the sort range
address after you’ve verified that each of the other lines of code were properly written and being
properly executed.
 
Search JabSto ::




Custom Search