我在创建一个数组时会遇到问题,该数组包含许多数据,然后将其合并到一个文件中。在从文件中读取信息,然后将它们放入另一个合并文件中的过程中,它所在的循环会发现 2042 错误。我在添加手表中发现它想要返回 #N/A,因为原始文件中的函数不返回任何内容。如何避免宏停止?我已经找到了跳过此记录的方法,但由于处理这些记录的经验不足,我无法将其插入到我的当前循环中。它停在这里"如果aOutput(1,outputCol(= aDataFromPivotFiltered(1,filteredCol(那么"请参阅下面的一小部分宏。
For outputCol = 1 To UBound(aOutput, 2)
For filteredCol = 1 To UBound(aDataFromPivotFiltered, 2)
If aOutput(1, outputCol) = aDataFromPivotFiltered(1, filteredCol) Then
For filteredRow = 2 To UBound(aDataFromPivotFiltered, 1)
aOutput(filteredRow, outputCol) = aDataFromPivotFiltered(filteredRow, filteredCol)
Next filteredRow
Exit For
End If
Next filteredCol
Next outputCol
我找到了下面,这还可以,但它应用了另一个宏。
Sub Test()
Dim varIn As Variant
[a1].FormulaR1C1 = "=NA()"
If IsError([a1].Value2) Then
varIn = "skip record"
Else
varIn = [a1].Value2
End If
End Sub
有没有人可以帮助我解决这个问题?无论我在这个主题中阅读了多少篇文章,它都会引起头痛。想不通。
首先测试错误,如下所示:
If Not IsError(aDataFromPivotFiltered(1, filteredCol) And Not IsError(aOutput(1, outputCol)) Then
If aOutput(1, outputCol) = aDataFromPivotFiltered(1, filteredCol) Then
For filteredRow = 2 To UBound(aDataFromPivotFiltered, 1)
aOutput(filteredRow, outputCol) = aDataFromPivotFiltered(filteredRow, filteredCol)
Next filteredRow
Exit For
End If
End If
这样,将跳过传递到数组中的任何公式错误。