答案1
在代码行后添加以下内容h = Replace(g, ",2)", "")
If IsNumeric(Mid(h, 2, 1)) Then
h = Replace(h, "=", "")
End If
它检查 后面的字符是否=
为数字。如果是,则=
删除 。您的代码将是:
Sub UndoRoundOff()
Dim x As Range
For Each x In Selection
f = x.Formula
g = Replace(f, "=ROUND(", "=")
h = Replace(g, ",2)", "")
If IsNumeric(Mid(h, 2, 1)) Then
h = Replace(h, "=", "")
End If
x.Formula = h
Next x
End Sub