如何将IFERROR应用于Excel中的所有单元格

我有很多有#DIV / 0的单元格! 所以我需要把IFERRORfunction。 有没有办法将此公式应用于所有单元格,而不是将公式手动放入每个单元格中?

我试过这个VBA代码,但我正在寻找更简单的东西。

Sub WrapIfError() Dim rng As Range Dim cell As Range Dim x As String If Selection.Cells.Count = 1 Then Set rng = Selection If Not rng.HasFormula Then GoTo NoFormulas Else On Error GoTo NoFormulas Set rng = Selection.SpecialCells(xlCellTypeFormulas) On Error GoTo 0 End If For Each cell In rng.Cells x = cell.Formula cell = "=IFERROR(" & Right(x, Len(x) - 1) & "," & Chr(34) & Chr(34) & ")" Next cell Exit Sub 'Error Handler NoFormulas: MsgBox "There were no formulas found in your selection!" End Sub 

谁能帮我?

也许这些版本中的一个会更容易教导。

 Sub apply_Error_Control() Dim cel As Range For Each cel In Selection If cel.HasFormula Then 'option 1 cel.Formula = Replace(cel.Formula, "=", "=IFERROR(") & ", """")" 'option 2 'cel.Formula = "=IFERROR(" & Mid(cel.Formula, 2) & ", """")" End If Next cel End Sub 

我提供了两种方法将IFERROR函数用作错误控制的“wapper” 。 要使用第二个选项,请先注释第一个选项,然后取消注释第二个选项。

select一个或多个单元格,然后运行macros; 通常虽然Alt + F8然后从工作表中运行