Home » excel » string – iserror formulae in excel

string – iserror formulae in excel

Posted by: admin May 14, 2020 Leave a comment

Questions:

In excel if I have the following

=match(“abc”,A:A,0)

if it errors then it throws some thing like

#value

so i tide this up by saying

=iserror((match(“abc”,A:A,0),”Not found”,match(“abc”,A:A,0) )

but this seems messy code.. running the same formula twice, can this be formated better to give the same result?

Cheers

How to&Answers:

Which version of Excel are you using? In Excel 2007 or later versions you can use IFERROR function to avoid repetition

=IFERROR(MATCH("abc",A:A,0),"Not found")

or in earlier versions you could employ COUNTIF

=IF(COUNTIF(A:A,"abc"),MATCH("abc",A:A,0),"Not found")

Answer:

I’m not aware of a built-in way to do this, but you could write your own VBA function:

Function GracefulError(varValue As Variant, strMessage As String) As Variant
    If IsError(varValue) Then
        GracefulError = strMessage
    Else
        GracefulError = varValue
    End If
End Function

Usage:

=GracefulError(match("abc",A:A,0), "Not found")