## Note See Chapter for information on using the If Then statement

0 Assign the value to the variable.

^0 Type End If to end the If Then statement.

Q Repeat steps 5 through 7 for each value.

### Exir a

VBA provides different functions for checking a value to make sure that it is the desired data type. You should check the data type of a value before assigning it to a variable or performing any type of operation. These functions ensure that no error messages occur if the wrong data type passes to a variable. Each of these functions return a Boolean value of True or False, indicating whether the value is the specified type.

 FUNCTION DESCRIPTION IsArray Checks to see if the specified value is an array. IsDate Checks to see if the specified value is a date. IsNull Checks to see if the specified value is Null. IsNumeric Checks to see if the specified value is numeric. IsObject Checks to see if the specified value is an object.

Typically you combine these VBA functions with an If Then statement that performs an action if the value is the appropriate data type. See Chapter 6 for more information on using If Then statements. For example, the following code only executes if the value of the NumVal variable is a number.

If IsNumeric(NumVal) Then

Total = Total + NumVal End If Var2 replacing (3, 1) with the cell location, Varl with the first variable and Var2 with the second variable.

■ If both values are numbers, Excel places the sum in the cell. Otherwise, Excel uses the value zero for the cells that do not contain a number.

Var2 replacing (3, 1) with the cell location, Varl with the first variable and Var2 with the second variable.

■ Excel assigns the sum of the variables to the cell. If either cell is not numeric, you can use a value of 0 in the equation.

• Switch to Excel and run the macro.

■ If both values are numbers, Excel places the sum in the cell. Otherwise, Excel uses the value zero for the cells that do not contain a number.