【问题标题】:How to insert only results of R1C1 formula calculation without inserting formulas如何仅插入 R1C1 公式计算的结果而不插入公式
【发布时间】:2016-03-22 21:42:48
【问题描述】:

有没有办法跳过将 R1C1 公式插入范围但只插入公式结果的步骤?我现在拥有的:

newColumn.FormulaR1C1 = "=MID(RC[-17],14,3)"
newColumn.Value = newColumn.Value

我想要类似的东西:

newColumn.Value = newColumn.FormulaR1C1 = "=MID(RC[-17],14,3)"

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    newColumn.Value = evaluate("MID(RC[-17],14,3)")

    【讨论】:

    • 我认为对于没有 R1C1 参考的公式可以采用这种方式。它返回给我一个#VALUE! 错误
    【解决方案2】:

    R1C1公式转换为A1类型的方法如下:

    Function MakeA1(R1C1Formula As String) As String
    
    MakeA1 = Application.ConvertFormula( _
        Formula:=R1C1Formula, _
        fromReferenceStyle:=xlR1C1, _
        toReferenceStyle:=xlA1, _
        ToAbsolute:=xlAbsolute)    
    End Function
    

    那么你可以这样使用它:

    Sub test()
        str1 = MakeA1("MID(RC[-17],1,3)")
        Range("B2").Value = Evaluate(str1)
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多