【问题标题】:How to ignore error indicated by clear green triangle?如何忽略由清晰的绿色三角形指示的错误?
【发布时间】:2017-05-19 08:59:03
【问题描述】:

我想从整个工作簿中清除 Excel “绿色三角形错误”

我准备了以下 VBA 代码。它没有清除错误。

在每个 Excel 工作表中花费更多时间(通过单击单元格的角并选择忽略错误)。

Sub IFERROR()
    Dim ws As Worksheet
    For Each ws In Worksheets
        On Error Resume Next
        Set frange = ws.Cells.SpecialCells(xlCellTypeFormulas)
        On Error GoTo 0
        If Not frange Is Nothing Then
            For Each c In frange
                If IsError(c.Value) Then
                    If c.Value = CVErr(xlErrDiv0) Then
                        c.Clear
                    End If
                End If
            Next c
        End If
        Set frange = Nothing
    Next ws
End Sub

【问题讨论】:

  • 绿色小三角形由您可以在文件>选项>公式>错误检查规则中设置的错误检查规则确定。
  • 是的,但是要删除它,我们需要选择特定的单元格角并单击全部忽略。
  • 点击离开后会在下次计算工作表时返回。但是,如果您更改规则,它一开始就不会出现。

标签: excel vba


【解决方案1】:

您可以使用以下方法完全关闭它们:

Application.ErrorCheckingOptions.BackgroundChecking = False

如果您希望它只影响一个文档,您可以在文档被激活/停用时打开/关闭它,也许存储之前的设置等。

【讨论】:

    【解决方案2】:

    你有两个选择:

    1. 关闭错误检查,在@Variatus 建议的选项中或使用@CLR 发布的代码。如果您使用此方法,即使重新启动 Excel,您也会关闭所有打开的文件的错误检查。

    2. 忽略/清除错误,就像您手动执行但使用代码一样:

      Dim rCell As Range
      Dim i As Integer
      
      For Each rCell In Your_Range
          For i = 1 To 9
              rCell.Errors(i).Ignore = True
          Next i
      Next rCell
      

      您可以通过仅清除您遇到的错误类型并避免循环来减少运行时间。这是类型列表:

      1. xlEvaluateToError
      2. xlTextDate
      3. xlNumberAsText
      4. xlInconsistentFormula
      5. xlOmittedCells
      6. xlUnlockedFormulaCells
      7. xlEmptyCellReferences
      8. xlListDataValidation
      9. xlInconsistentListFormula

    您可以写Errors(5).IgnoreErrors(xlOmittedCells).Ignore 更清楚。

    【讨论】:

      【解决方案3】:

      mikerickson shared an excellent solution 禁用错误检查并在关闭时恢复用户的原始设置:

      Dim PriorErrorChecking As Boolean
      
      Private Sub Workbook_Open()
       PriorErrorChecking = Application.ErrorCheckingOptions.BackgroundChecking
       Application.ErrorCheckingOptions.BackgroundChecking = False 
      End Sub 
      
      Private Sub Workbook_BeforeClose(Cancel As Boolean) 
       Application.ErrorCheckingOptions.BackgroundChecking = PriorErrorChecking
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-23
        • 1970-01-01
        • 2014-06-18
        • 1970-01-01
        • 2018-08-09
        • 1970-01-01
        • 2012-08-05
        相关资源
        最近更新 更多