Identifying Bugs

Before you can do any debugging, you must determine whether a bug actually exists. You can tell that your macro contains a bug if it doesn't work the way it should. (Gee, this book is just filled with insight, isn't it?) Usually, but not always, you can easily discern this.

A bug often (but not always) becomes apparent when Excel displays a runtime error message. Figure 13-1 shows an example. Notice that this error message includes a button labeled Debug. More about this later in the "About the Debugger" section.

It's important to remember that bugs often appear when you least expect them. For example, just because your macro works fine with one data set doesn't mean you can assume it will work equally as well with all data sets. The best debugging approach is thorough testing, under a variety of real-life conditions.

Figure 13-1:

An error message like this often means that your VBA code contains a bug.

0 0

Post a comment