Run to Cursor

Many times when you're executing code, you don't want to run every line of code line by line, but executing the entire procedure at once doesn't help you isolate the problem. And it is very tedious to execute every line of the loop each time a long loop needs to run. For example, consider the following code:

Sub CoffeeTime()

Dim curLatteAllowance As Currency Dim curLattePrice As Currency Dim intNumLattes As Integer Dim curTotalExpenses As Currency curLattePrice = 3.5 curLatteAllowance = InputBox( _

"Enter the amount of money you have for lattes.", _ "Latte Allowance") While curTotalExpenses < curLatteAllowance intNumLattes = intNumLattes + 1

curTotalExpenses = curTotalExpenses + curLattePrice


Debug.Print intNumLattes

MsgBox "You can purchase " & intNumLattes & " lattes.", vbOkOnly, "Total Lattes" End Sub

If you have $350 to spend on lattes, the While...Wend loop will run 100 times. Pressing F8 to step through that long of a loop can be quite tiresome. Thankfully, there is a shortcut. If you're not worried that the loop is producing incorrect data, you can place your cursor in the Debug.Print intNumLattes line and press Ctrl+F8. Your procedure will run until it reaches the Debug.Print line, where it halts and is highlighted. You can then press F8 to execute just the highlighted line of code or press F5 to continue execution until the end of the procedure.

Was this article helpful?

0 0

Post a comment