作者:杨子忧愁_347 | 来源:互联网 | 2023-05-19 15:37
SotheotherdayIwasgettingsomestrangesumvaluesandIwascompletelystumped.Igaveuponus
So the other day I was getting some strange sum values and I was completely stumped. I gave up on using a sum function in VBA and just added the values the long way (through loops), but then I read somewhere that using the sum functions in VBA isn't always reliable for developers? (I can't find the post anymore, but I'm still looking for it).
所以有一天我得到了一些奇怪的总和值,我完全被难倒了。我放弃在VBA中使用sum函数,只是添加了很长的值(通过循环),但后来我在某处读到使用VBA中的sum函数并不总是对开发人员可靠? (我找不到帖子了,但我还在找它)。
Is there any truth to this? I know many people have different ways to get the sum from a range of cells - without being too opinionated, which one of these will return the most exact result?
有没有道理呢?我知道很多人有不同的方法可以从一系列细胞中获得总和 - 而不是过于自以为是,其中一个会返回最准确的结果?
Sub testsums()
Dim metric1 As Integer, metric2 As Integer, metric3 As Integer
metric1 = Application.Sum(Range(("A1"), ("Z1")))
metric2 = Application.WorksheetFunction.Sum(Range(("A1"), ("Z1")))
metric3 = WorksheetFunction.Sum(Range(("A1"), ("Z1")))
End Sub
I'm working to reproduce my error - basically when looping through many rows (15,000+) and getting sums, some were returning zeroes where they shouldn't have been.
我正在努力重现我的错误 - 基本上当循环通过许多行(15,000+)并获得总和时,有些人返回的零点应该不存在。
1 个解决方案