0
我有很多具有#DIV/0的单元格!所以我需要把IFERROR函数。有没有办法将此公式应用于所有单元格,而不是将公式手动放入每个单元格中?如何将IFERROR应用于Excel中的所有单元格
我试过这个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
任何人都可以帮我吗?
这段代码对我来说很不错。有什么问题? – Jeeped
这对我来说不是问题,但我想使用简单的东西,并教导不了解编程基础知识的其他人使用它。 – user3619789
我唯一可能想到的问题是'x = Mid(cell.Formula,2)'而不是'x = cell.Formula',以便从公式中删除任何前导的'='。或者 - 更高级一点 - 你也可以使用:Iif(InStr(1,cell.Formula,“=”)> 0,Mid(selection.Formula,2),cell.Formula)'。 – Ralph