Search code examples
vbaexcelskip

Skip if Result is Not a Numeric - Excel VBA


Warmest greeting, Currently I have the code:

result = Range("E" & n) - Range("D" & n)

There will be a row of text which give the result not a numeric, I tried to add these code:

result = Range("E" & n) - Range("D" & n)
Lvalue = IsNumeric(result)
If Lvalue = False then
    n = n + 1
else
    'other code here
End If

But it still give me "Type Mismatch" error...How can I execute code

n = n + 1

when the result is not a numeric? Any effort is appreciated! Thanks!


Solution

  • if you are subtracting two number which is not numeric you may get the error .

    So try to find out the both the cell is numeric or not and do your stuffs.

    If IsNumeric(Range("E" & n)) = True And IsNumeric(Range("D" & n)) = True Then
        result = Range("E" & n) - Range("D" & n)
        n = n + 1
    Else
        'other code here
    End If