【发布时间】:2021-10-31 16:31:40
【问题描述】:
我正在为以下代码中的 iferror 函数中的字符串而苦苦挣扎。我希望字符串是可变的,如果出现错误,则会弹出一个输入框,用于指定用户想要的字符串。
Sub test_IFERROR()
Dim frange As Range, xcell As Range
Dim xAddress As String
Dim xStr As String
On Error Resume Next
xAddress = Application.ActiveWindow.RangeSelection.Address
Set frange = Application.InputBox("Please select a range", "Kutools for Excel", xAddress, , , , , 8)
Set frange = ws.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0
If Not frange Is Nothing Then
xStr = Application.InputBox("Replace blank cells with what?", "Kutools for Excel")
xUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
For Each xcell In frange
c.Formula = "=IFERROR(" & Right(c.Formula, Len(c.Formula) - 1) & ","" & xStr & "")"
Next xcell
End If
Set frange = Nothing
End Sub
【问题讨论】:
-
试试:
c.Formula = "=IFERROR(" & Mid$(c.Formula, 2) & ",""" & xStr & """)" -
谢谢你,但它不起作用。
-
它给出一个错误并弹出调试屏幕
-
c.Formula = "=IFERROR(" & Right(c.Formula, Len(c.Formula) - 1) & ","" & xStr & "")" 问题出在这线。我试过你的,但它不起作用
-
我的代码有几个错误。你的一个工作得很好。谢谢你帮助我。
标签: excel vba string excel-formula