dlofrodloh
dlofrodloh

Reputation: 1744

How to deal with #VALUE! type mismatch

I'm building an excel macro and I've encountered a problem when a cell result is "#VALUE!". The macro has already copy and pasted the values as text, when it tries to store a cell.value in a string which has "#VALUE!" in it (even though its text), there is a type mismatch error.

The following code doesn't work, still get the type mismatch

    If Cell.Value <> "#VALUE!" Then
        TempString = Cell.Value
        StringPart = Left(TempString, 3)
    End If

What's a solution for this?

Upvotes: 0

Views: 102

Answers (2)

Siphor
Siphor

Reputation: 2534

If Vartype(Cell.Value) <> vbError Then
    TempString = Cell.Value
    StringPart = Left(TempString, 3)
End If

Upvotes: 3

Mitja Bezenšek
Mitja Bezenšek

Reputation: 2533

You could use ISERROR function: http://www.techonthenet.com/excel/formulas/iserror.php

Upvotes: 1

Related Questions