karamell
karamell

Reputation: 713

VBA excel IsError function for special case

I'm looking for a function similar to the IsError function which returns TRUE if the input is fishy and FALSE otherwise:

I have two ranges rng1, rng2 and I want to perform this operation

IsError( rng1.value / rng2.value)

The function should return TRUE if rng1.value or rng2.value one range contains a string, is empty or rng2.value=0

Is there a similar function or some nice way to state these conditions? or should I just do an If-statement with all of the conditions as or?

Upvotes: 0

Views: 338

Answers (1)

John Bustos
John Bustos

Reputation: 19564

You could do something like this (Not tested, but it should do the trick):

  Function CheckError(rng1 As Range, rng2 As Range) As Boolean

     On Error GoTo FoundError
     Dim x As Integer

     x = rng1.Value / rng2.Value

     CheckError = False
     Exit Function

  FoundError:
     CheckError = True

  End Function

Upvotes: 1

Related Questions