这就是我正在尝试做的事情:我在 (D) 列中有 StockOH,我想知道每个金额可以覆盖多少天的销售。因此,例如,如果 D2 中的 stockOH 值大于值 E2:E5 的总和但小于 Sum(E2:E6),这意味着我可以涵盖 4 天的销售。
我正在使用嵌套到 for 循环的 Do until 函数。我不确定为什么第一个结果是正确的,而下一个结果不是
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim y, x, Ssellout As Double
'loop thorugh the stock values in column D
For y = 2 To 5
'Get each amount of stock
Ssellout = Cells(y, 5).Value
x = y
'FInd the breakout point when sum of sellout is higher than stockOH
Do Until Cells(y, 4).Value < Ssellout
'Add 1 to the counter in case condition is not valid
x = x + 1
'REport value found as a breakeven
Cells(y, 6).Value = x
'Add another day of sales to the sum of sales
Ssellout = Ssellout + Cells(x, 5).Value
Loop
MsgBox (y)
Next
End Sub