VBA无法处理input了#Value的字段

我有一个每个循环,当涉及到#Valueinput的字段时,它会被绊倒。 我有一个解决方法,因为我不断收到Ge0eral ,我需要离开,但现在我无法通过inputGe0eral过去的领域。

下面是一个示例表和代码。

我想要的是打印#Value或忽略与#Value在一起的字段。

 Sub TableMessup() Dim myTable As Range Set myTable = Range("A1:D3") Dim mycell As Range Dim tempstr As String For Each mycell In myTable tempstr = Format(mycell.Value, mycell.NumberFormat) If tempstr = "Ge0eral" Then Debug.Print mycell.Value Else Debug.Print Format(mycell.Value, mycell.NumberFormat) End If Next mycell End Sub 
 +---+---+---------+--------+ | a | b | c | d | +---+---+---------+--------+ | 1 | 4 | 5 | 50.00% | | 2 | t | #VALUE! | 20.00% | +---+---+---------+--------+ 

而不是使用Format()的string使用Mycell.Text而不是Mycell.Value。

你不能打印一个错误值,因为它不是一个string,它是一个errortypes。

您可以改为使用单元格的.Text属性。

或者,您可以使用一些条件逻辑,如:

 For Each mycell In myTable If IsError(myCell.Value) Then Debug.Print "Error at " & myCell.Address Else tempstr = Format(mycell.Value, mycell.NumberFormat) If tempstr = "Ge0eral" Then Debug.Print mycell.Value Else Debug.Print Format(mycell.Value, mycell.NumberFormat) End IF End If Next mycell