Skip to main content

Error object

Table of contents
  1. Remarks
  2. Example

Represents a spreadsheet error for a range.

Remarks

This object works for ranges containing only one cell.

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

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

Example

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

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>