In this example, we??™ll add a watch to the GetSalesTotal function and set it to break when
the value is True.
1. Open the VBE and open Standard Module2.
2. Display the GetSalesTotal function.
3. Right-click any occurrence of the variable cell in the For Each...Next loop.
4. Select Add Watch from the shortcut menu, as shown in Figure 7-34.
Figure 7-34. Selecting the Add Watch command
5. Enter the information shown in Figure 7-35 into the Add Watch dialog box.
CHAPTER 7 n DEBUGGING AND ERROR HANDLING 273
Figure 7-35. Adding a watch expression
nTip If you put the insertion point anywhere on the variable you want to watch and add the watch, the
variable name will automatically be inserted in the Expression box for you.
6. Click OK to close the Add Watch dialog box.
7. If not already open, open the Watch window in the VBE by clicking View ?¤Watch
Window. Figure 7-36 shows the Watch window with our expression added.
Figure 7-36.Watch expression added to Watch window
Notice that the value is currently out of context because the code is not yet running.
8. Run the AddSalesTotal macro from Worksheet1 in Excel. The code enters break mode
in the For Each...Next loop, and the Watch window shows us that the value of our
condition is True, as shown in Figure 7-37.
CHAPTER 7 n DEBUGGING AND ERROR HANDLING 274
Figure 7-37.Watch window showing the true condition with the code in break mode
9. Press F5 to continue running the code. Any time the watch encounters a cell value of
less than 30, the code will enter break mode.
Pages:
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259