Check Results
In many situations, you need to check the result of an operation to tell if it succeeded. The result-checking functions in Visual Basic let you test results before you take actions that might otherwise cause an error. Table 3-16 lists the result-checking functions.
Table 3-16. Visual Basic result-checking functions
Category |
Function |
Use to |
---|---|---|
Boolean tests |
|
Tell if a variable is an array |
|
Tell if a variable contains data that can be converted to a | |
|
Tell if a variable has not yet been initialized | |
|
Tell if a variable contains an | |
|
Tell if a | |
|
Tell if a variable contains no valid data | |
|
Tell if a variable contains a value that can be converted to a number | |
|
Tell if a variable is a reference to a valid object | |
Type tests |
|
Get the name of the variable’s type as a string |
|
Test the type of a variable within an | |
|
Get the variable’s type as a |
Most of these tests are used with variables that were declared as Variant
or Object
data types. Those types of variables can contain many different kinds of data, so it is often necessary to test what the variable contains before proceeding in code.
There are several common uses of this in Excel. The first is ActiveSheet
.property
, which may refer to a Worksheet
, Chart
, or other object:
Sub ChangeSheets( ) Select ...
Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.