Microsoft Office Tutorials and References
In Depth Information
Testing and Debugging Your Functions
To help identify the source of the runtime error, insert the following Sub procedure:
Sub Test()
x = REVERSETEXT(“Hello”)
MsgBox x
End Sub
This Sub procedure simply calls the REVERSETEXT function and assigns the result to a variable
named x . The MsgBox statement displays the result.
You can execute the Sub procedure directly from the VB Editor. Simply move the cursor
anywhere within the procedure and choose Run
Run Sub/UserForm (or just press F5). When you
execute the Test procedure, you see the error message that is shown in Figure 23-8.
Figure 23-8: A runtime error identified by VBA.
Click the Debug button, and the VB Editor highlights the statement causing the problem (see
Figure 23-9). The error message does not tell you how to correct the error, but it does narrow
your choices. After you’ve identified the statement that’s causing the error, you can examine it
more closely, or you can use the Immediate window (see the sidebar, “Using the Immediate
window”) to help locate the exact problem.
Search JabSto ::

Custom Search