在VBA中基于公式错误/值设置variables

我试图计算一个工作表(设置在手动计算),直到没有更多的错误。 我有下面的代码,但它似乎不识别我设置的variables,因为这些variables的值是一个公式的结果,而不是实际上在单元格中作为一个值。 我在另外一个有关使用工作表函数的相关主题上看到了一个问题,但是一直无法看到我能如何适应我的代码。 通常如果我运行这个过程没有VBA代码,我做手动计算5-6次,但代码我想更容纳。 我的代码的其余部分工作,这只是这个部分搞乱了这个过程。 我想我可以像平常一样在一个循环中计算一些任意数量的calc,但是如果可能的话,我希望它只在下面的两个错误出现时才计算。 请参阅下面的代码段。

Dim n As Variant Dim na As Variant n = "#N/A Requesting Data..." na = "#N/A Invalid Override" Application.ScreenUpdating = False Application.Calculation = xlCalculationManual For Each Cell In Range("AZ13:BQ82") If Cell.Value = n Then Sheet1.Calculate End If Next For Each Cell In Range("AZ13:BQ82") If Cell.Value = na Then Sheet1.Calculate End If Next 

IsError是你的朋友

  Application.ScreenUpdating = False Application.Calculation = xlCalculationManual For Each Cell In Range("AZ13:BQ82") If IsError(Cell.Value) Then Sheet1.Calculate End If Next