I have an Excel spreadsheet. I'm trying to test whether the formula results in an error. VBA has VBA.IsError
and I'm looking for an equivalent in VB.net.
Dim CurrCell As Excel.Range = ws.Range("B10")
CurrCell.Formula = "=DATEVALUE(-1)" 'results in #VALUE! error
CurrCell.Select()
'doesn't detect error
If Microsoft.VisualBasic.IsError(CurrCell.Value) Then
Debug.Print("error")
Else
Debug.Print("not error")
End If
'doesn't detect error; shows as VariantType.Integer
Debug.Print(VarType(CurrCell.Value))
If VarType(CurrCell.Value) = VariantType.Error Then
Debug.Print("error")
Else
Debug.Print("not error")
End If
How do I detect whether the result of the formula is an error using VB.net?