SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 244 | Next

Jim DeMarco

"Pro Excel 2007 VBA"


1. In the Excel window, open Worksheet1 in the DebugExample01.xlsm file.
2. Open the Developer ribbon and click the Macros command to open the Macros dialog
box.
3. Run the AddSalesTotal macro.
A type mismatch error occurs, as shown in Figure 7-27.
Figure 7-27. Type mismatch error 13
4. Click the Debug button to put the code in break mode.
5. Open the Locals window by choosing View ?¤ Locals Window.
The Locals window will open, as shown in Figure 7-28.
Looking at the Locals window in Figure 7-28, we see the values for the GetSalesTotal
function and for the variables currReturn, temp, and cell.We also see the values for the range
we pass into the function, RangeToTotal.
GetSalesTotal and currReturn both have a value of 0, as they are not set until the end of
the function. The variable temp, which is set during the loop that walks the range, has a value
of 303 so far.
The cell variable is a bit different, as is the RangeToTotal variable. These variables are references
to range objects. This means that they have more than just a value. They have
properties??”and lots of them!
6. Click the plus sign to the left of the cell variable.
7. Scroll down until you see the Value2 property.
CHAPTER 7 n DEBUGGING AND ERROR HANDLING 269
Figure 7-28. The Locals window displays values for all in-scope variables.
The Value2 property stores the current cell??™s value. In this case, it??™s the string N/A. It looks
like someone didn??™t have a value for DVD sales in the East region, and entered a string rather
than leaving it blank or entering a 0.


Pages:
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256