我試圖添加= IFERROR函數到Excel公式。在活動單元格中的原始公式示例:=A1/B3
,示例新公式:=IFERROR(A1/B3;0)
。但它會導致運行時錯誤。消息框中顯示的公式似乎是正確的。Add = IFERROR函數公式
我已經測試了相同的代碼,用變量添加括號給公式:First_part = "=(" and Last_Part = ")"
,它工作正常。我也用IF函數使用變量測試了相同的代碼: First_part = "=IF(F1=2;" and Last_Part = ";0)"
,這也導致運行時錯誤。
Sub Adding_IFERROR()
Dim Cell_Content As String
Dim First_Part As String
Dim Last_Part As String
Dim New_Cell_Content As String
First_Part = "=IFERROR("
Last_Part = ";0)"
'Remove the initial "=" sign from original formula
Cell_Content = ActiveCell.Formula
Cell_Content = Right(Cell_Content, Len(Cell_Content) - 1)
'Writing new formula
New_Cell_Content = First_Part & Cell_Content & Last_Part
MsgBox New_Cell_Content, vbOKOnly
ActiveCell.Formula = New_Cell_Content
End Sub
是否有任何明顯的原因,爲什麼它不起作用?
好抓!我正要將此問題標記爲[this]的重複(http://stackoverflow.com/questions/32902128/how-to-apply-iferror-to-all-cells-in-excel/32902671#32902671)當我意識到你會發現它失敗的真正原因。 – Jeeped