Search code examples
vbaref

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


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 ?


Solution

  • 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