我在许多讨论中找到了如何在Excel中实现此目标的方案,但我的目的是在VBA中捕获REF!错误,而不是在Excel本身中。这是否可能?
If IsError(cell.Value) Then
If cell.Value = CVErr(xlErrName) Then
...
End If
End If
If cell.Value = CVErr(xlErrRef) Then
...
End If
cell
为空,会发生什么? - MikeDSub CheckRef()
Dim CheckRange As Range, CheckCell As Range
Set CheckRange = [A1:D10] ' as per app
For Each CheckCell In CheckRange
If IsError(CheckCell) And _
CVErr(CheckCell) = CVErr(2023) Then ' 2023 --> xlErrRef
MsgBox ("#REF! in " & CheckCell.AddressLocal)
Exit Sub ' exit after first #REF! found
End If
Next CheckCell
End Sub
例子
Sub CheckRef()
CheckCell
包含数字 2023
,会发生什么? - GSergIsError(CheckCell)
...更改答案。 - MikeD