Stepping through VBA Procedures

Stepping through the code means running one statement at a time. This allows you to check every line in every procedure that is encountered. To start stepping through the procedure from the beginning, place the insertion point anywhere inside the code of your procedure and choose Debug | Step Into, or press F8. The Debug menu contains several options that allow you to execute a procedure in the step mode (see Figure 13-14).

When you run a procedure one statement at a time, Visual Basic executes each statement until it encounters the End Sub keywords. If you don't want Visual Basic to step through every statement, you can press F5 at any time to run the rest of the procedure without stepping through it.

j Microsoft Visual Basic - Cbapl3,wls [break] - [Breaks (Code)]

^ File £dt View insert Ffirrnat

Pro|ect - Debugging m s||aj

R ^ Debugging (Chap 13,xls)

B "ifj Microsoft Excel Objects ® Sheet 1 (Sheet 1) SQ Sheet? (Sheet2) Sheet3 (Sheet3) ^ ThisWorkbook Modules Breaks

Properties - Breaks

[Breaks Module Alphabetic | categorized |

&ebug | Bun lools Add-Ins Window Help

Comple Debugging

Step Into F8

Step Over Shft+F3

Run To Cursor Ctrl+FS fidd Watch,»

Quick Watch... Shit+F9

^ Toggle Breakpoint F9

gear All Breakports Ctrt+Sl"rft+F9

Set yext Statement Ctrl+F9 ^ Show Next Statement

Properties - Breaks

[Breaks Module Alphabetic | categorized |



;1). Select Select tCcji; i). Select ctiorr SXt

Sub WhatDateO Dim curDatB As Date Dim newDale As Date Dim k As Integer curDale = Dale ■For (=1 To 365

Figure 13-14: The Debug menu offers many commands for stepping through VBA procedures.

0 0

Post a comment