Option
Explicit
Dim
Spalte
As
Long
, Grenzwert
As
Double
, dKum
As
Double
Sub
Test()
Spalte = 1: Grenzwert = 20
Kumu 1
End
Sub
Sub
Kumu(Start
As
Long
)
Dim
x
As
Long
, y
As
Long
With
Columns(Spalte)
For
x = Start
To
.Cells(.Cells.Count).
End
(xlUp).Row
If
.Cells(x).Value >= Grenzwert
Then
.Cells(x).Offset(, 1).Value = Grenzwert
.Cells(x).Offset(, 2).Value = .Cells(x).Offset(, 1).Value - Grenzwert
Else
y = KumIt(x, .Cells(x).Value)
.Cells(y).Offset(, 1).Value = Grenzwert
.Cells(y).Offset(, 2).Value = dKum - Grenzwert
dKum = 0
x = y
End
If
Next
x
End
With
End
Sub
Function
KumIt(Rw
As
Long
, Wert
As
Double
)
As
Long
Dim
x
As
Long
, Kum
As
Double
With
Columns(Spalte)
Kum = Kum + Wert
For
x = Rw + 1
To
.Cells(.Cells.Count).
End
(xlUp).Row
Kum = Kum + .Cells(x).Value
If
Kum >= Grenzwert
Then
Exit
For
Next
x
dKum = Kum
KumIt = x
End
With
End
Function