Share via


Error Object

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Errors
Aa661409.parchild(en-us,office.10).gifError

Represents a spreadsheet error for a range.

Using the Error object

Use the Item property of the Errors object to return an Error object.

Once an Error object is returned, you can use the Value property, in conjunction with the Errors property to check whether a particular error checking option is enabled. 

The following example creates a formula in cell A1 referencing empty cells, and then it uses Item(index), where index identifies the error type, to display a message stating the situation.

  Sub CheckEmptyCells()

    Dim rngFormula As Range
    Set rngFormula = Application.Range("A1")

    ' Place a formula referencing empty cells.
    Range("A1").Formula = "=A2+A3"
    Application.ErrorCheckingOptions.EmptyCellReferences = True

    ' Perform check to see if EmptyCellReferences check is on.
    If rngFormula.Errors.Item(xlEmptyCellReferences).Value = True Then
        MsgBox "The empty cell references error checking feature is enabled."
    Else
        MsgBox "The empty cell references error checking feature is not on."
    End If

End Sub

Note: Be careful not to confuse the Error object with error handling features of Visual Basic.