Excel) (错误对象

代表区域的电子表格错误。

备注

此对象适用于仅包含一个单元格的区域。

使用 Errors 对象的 Item 属性可返回 Error 对象。

返回 Error 对象后,可以将 Value 属性与 Range 对象的 Errors 属性结合使用,以检查是否启用了特定的错误检查选项。

注意

请注意,不要将 Error 对象与 Visual Basic 的错误处理功能混淆。

示例

以下示例在单元格 A1 中创建一个引用空单元格的公式,然后使用 Item (索引) (其中 index 标识错误类型)显示一条说明情况的消息。

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

属性

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。