在运行以下代码时,将intEarn 样式添加到自身时,变量intEarn不会从0更改intEarn = intEarn + (...)。
我在整个代码中都放置了消息框,以便准确地看到每次计算的内容,不管是什么原因,不管变量中的intEarn = intEarn + (...)内容为何总是产生0 (...)。
Dim ovr As Range
Set ovr = cells.Find("Overview").Offset(2, 0)
Dim intEarn As Long
intEarn = 0
...
x = 0
Do until IsEmpty(ovr.Offset(x, 0))
'The following line results in 0
intEarn = intEarn + (ovr.Offset(x, 0).Offset(0, 1).Value * ovr.Offset(x,0).Offset(0, 2).Value)
'While the next line of code results in the proper number
MsgBox ("Correct: " & ovr.Offset(x, 0).Offset(0, 1).Value * ovr.Offset(x, 0).Offset(0, …Run Code Online (Sandbox Code Playgroud)