当前位置: 动力学知识库 > 问答 > 编程问答 >

excel - How to insert only results of R1C1 formula calculation without inserting formulas

问题描述:

Is there a way to skip a step of inserting a R1C1 formula into range but insert only formula results? What I have now:

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

newColumn.Value = newColumn.Value

I'd like to have something like:

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

网友答案:

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

网友答案:

Here is how to convert R1C1 formula to A1 type:

Function MakeA1(R1C1Formula As String) As String

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

Then you can use it so:

Sub test()
    str1 = MakeA1("MID(RC[-17],1,3)")
    Range("B2").Value = Evaluate(str1)
End Sub
分享给朋友:
您可能感兴趣的文章:
随机阅读: