VBAmacros出来的excel公式出乎意料地改变了
我有下面的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
但是,由于某些原因,在运行macros后的实际电子表格中,为范围内的所有单元格填充的实际公式为:
= 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() )-MONTH(DATE(2016; 1; 1)))
如果它是相关的,我的区域设置使用;
而不是在公式中
所以我也发布这个答案以及:你可以改变SumSQ.Formula
SumSQ.Formular1C1
?