How to check that Excel cell contains REF! error in VBA

Edgar Navasardyan picture Edgar Navasardyan · Jan 11, 2016 · Viewed 11.3k times · Source

I found many discussions on how to do it in Excel, but my goal is to capture REF! error in VBA, not in Excel itself. Is it possible ?

Answer

GSerg picture GSerg · Jan 11, 2016
If IsError(cell.Value) Then
    If cell.Value = CVErr(xlErrName) Then
        ...
    End If
End If

The original code is wrong and will give a Type Mismatch error if the cell does not contain an error.

If cell.Value = CVErr(xlErrRef) Then
    ...
End If