SUM公式VBA [英] SUM formula VBA
本文介绍了SUM公式VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试计算vba中更改单元格范围的总和。不幸的是,单元格值是变量。我似乎无法得到以下公式。
I am trying to calculate the sum of changing cell range in vba. Unfortunately the cell values are variables. I can't seem to get the following formula to work.
Private Sub calcOverheadRate(startCell As Integer, endCell As Integer)
Total = endCell + 1
Range("D" & Total).Formula = "=SUM("D" & startCell & ":" & "D" & endCell)"
End Sub
我收到编译错误:预期:结束语句
I get compile error: "Expected: end of statement
要解决这个问题问题我把函数改成了,
To solve this problem I changed the function to,
Private Sub calcOverheadRate(startCell As Integer, endCell As Integer)
Dim start As String
Dim endC As String
start = "D" & CStr(startCell)
endC = "D" & CStr(endCell)
Total = endCell + 1
Range("D" & Total).Formula = "=SUM(start:endC)"
End Sub
该函数编译好,当我运行它,单元格中的值是#NAME,它在哪里引用 SUM(start:endC)
不 SUM(D5:D23)
....
The function compiles fine, when I run it, the value in the cell is "#NAME" where it references SUM(start:endC)
not SUM(D5:D23)
....
任何想法如何t o解决这个将不胜感激。
Any thoughts on how to solve this would be appreciated.
推荐答案
引号是问题:
Range(D& ;总计).Formula == SUM(& startCell&& endCell&)
这篇关于SUM公式VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文