Share via


WorksheetFunction.IfError Method

Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula. Use the IfError function to trap and handle errors in a formula.

Namespace:  Microsoft.Office.Interop.Excel
Assembly:  Microsoft.Office.Interop.Excel (in Microsoft.Office.Interop.Excel.dll)

Syntax

'Declaration
Function IfError ( _
    Arg1 As Object, _
    Arg2 As Object _
) As Object
'Usage
Dim instance As WorksheetFunction
Dim Arg1 As Object
Dim Arg2 As Object
Dim returnValue As Object

returnValue = instance.IfError(Arg1, Arg2)
Object IfError(
    Object Arg1,
    Object Arg2
)

Parameters

  • Arg1
    Type: System.Object

    Value - the argument that is checked for an error.

  • Arg2
    Type: System.Object

    Value_if_error - the value to return if the formula evaluates to an error. The following error types are evaluated: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!.

Return Value

Type: System.Object

Remarks

If value or value_if_error is an empty cell, IfError treats it as an empty string value ("").

If value is an array formula, IfError returns an array of results for each cell in the range specified in value. See the second example below.

See Also

Reference

WorksheetFunction Interface

WorksheetFunction Members

Microsoft.Office.Interop.Excel Namespace