如何处理#VALUE! types不匹配

我正在构build一个excelmacros,当单元格结果是“#VALUE!”时,我遇到了一个问题。 当macros尝试将一个cell.value存储在一个string中时,macros已经复制并粘贴了这些值,该string中有“#VALUE!”。 在它(即使它的文本),有一个types不匹配的错误。

下面的代码不起作用,仍然得到types不匹配

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

这是什么解决scheme?

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

您可以使用ISERRORfunction: http : //www.techonthenet.com/excel/formulas/iserror.php