简体   繁体   English

Excel VBA求和函数

[英]Excel VBA Sum Function

I got a problem with sum of rows formula in vba. 我在vba中的行总和公式有问题。 I am using the below code. 我正在使用以下代码。 When I check the value in Range("H3").Formula its giving me the correct value =SUM(C5:G5) 当我检查Range("H3").Formula的值给我正确的值=SUM(C5:G5)

But the problem is its not reflecting in the excel cell. 但是问题是它没有反映在excel单元中。

Range("H3").Formula = "=SUM(" & Range(Cells(5, 3), Cells(5, 7)).Address(False, False) & ")"

You need to fully qualify the cells (notice the dots). 您需要完全限定单元格(注意点)。 Try this 尝试这个

'~~> Replace this with the relevant sheet
With Sheets("Sheet1")
    .Range("H3").Formula = "=SUM(" & _
                          .Range(.Cells(5, 3), .Cells(5, 7)).Address(False, False) & _
                          ")"
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM