来自VBA宏的excel公式的意外更改

时间:2016-06-21 07:32:32

标签: excel vba excel-vba

我有以下VBA示例代码,应使用与我在代码中定义的公式相同的公式填充SumSQ范围

  
    

= SUMSQ(RC13-RC11,RC16-RC14,RC19-RC17,RC22-RC20,RC25-RC23)/(MONTH(TODAY()) - 月(DATE(2016,1,1)))

  
Sub Prep()
    Dim Sh As Worksheet
    Dim CBS As Range
    Dim SumSQ As Range

    'Set range from C3 to final row of column C
    Set Sh = Worksheets("Sheet1")
    With Sh
        Set CBS = .Range("C6:C" & .Range("C" & .Rows.Count).End(xlUp).Row)
        Set SumSQ = .Range("AV6:AV" & CBS.End(xlDown).Row)
    End With

    SumSQ.Formula = "=SUMSQ(RC13-RC11,RC16-RC14,RC19-RC17,RC22-RC20,RC25-RC23)/(MONTH(TODAY())-MONTH(DATE(2016,1,1)))"

End Sub

但是,出于某种原因,在运行宏之后的实际电子表格中,为该范围内的所有单元格填充的实际表格是:

  
    

= SUMSQ(R [7] C [423] -R [5] C [423]; R [10] C [423] -R [8] C [423]; R [13] C [423] -R [11] C [423]; R [16] C [423] -R [14] C [423]; R [19] C [423] -R [17] C [423])/(MONTH( TODAY()) - 月(DATE(2016; 1; 1)))

  

如果相关,我的区域设置会在公式中使用;而不是,

1 个答案:

答案 0 :(得分:1)

所以我也将此作为答案发布: 您可以将SumSQ.Formula更改为SumSQ.Formular1C1吗?