代码之家  ›  专栏  ›  技术社区  ›  berwt

拒绝使用IFERROR粘贴公式

  •  1
  • berwt  · 技术社区  · 7 年前

    我不知道为什么,但很显然,具有讽刺意味的是,VBA在这一行中给出了一个错误。

    Range("OptionH").Formula = "=IFERROR((RC[1]-RC[-1])/RC[1];0)"
    

    当我只保留公式时 "=(RC[1]-RC[-1])/RC[1]" 没有问题。所以这一定和iferror有关。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Vityata    7 年前

    要查看发生了什么,请执行以下小技巧,将公式转换为VBA:

    • 在Excel中编写公式,这样就可以了。
    • 使用公式选择单元格。
    • 运行此代码:

    Public Sub PrintMeUsefulFormula()
    
        Dim strFormula  As String
        Dim strParenth  As String
    
        strParenth = """"
    
        strFormula = Selection.Formula
        strFormula = Replace(strFormula, """", """""")
    
        strFormula = strParenth & strFormula & strParenth
        Debug.Print strFormula
    
    End Sub
    

    查看即时窗口 Ctrl键 + G .