Excel) (錯誤物件

代表某個範圍的試算表錯誤。

註解

此物件適用於只包含一個儲存格的範圍。

使用 Errors 物件的 Item 屬性來傳回 Error 物件。

傳回 Error 物件之後,您可以使用 Value 屬性與 Range 物件的 Errors 屬性搭配使用,以檢查是否啟用了特定的錯誤檢查選項。

注意事項

請小心不要將 Error 物件與 Visual Basic 的錯誤處理功能混淆。

範例

下列範例會在儲存格 A1 中建立參照空白儲存格的公式,然後使用 Item (index) ,其中 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 支援與意見反應。