1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Private Sub CommandButton1_Click()
Dim f As Long, r As Long, C As Long, J As Long
f = ActiveCell.Row
r = Cells(f, 3).Value
C = 0
J = 0
For i = f To 2 Step -1
If C + Cells(i, 4).Value <= r Then
C = C + Cells(i, 4): Cells(f, 14) = C
J = J + 1
End If
Next i
X = f - J
If IsNumeric(Cells(X, 4)) Then
Cells(f, 15).Value = Cells(f, 14).Value + Cells(X, 4).Value
Else
MsgBox "Données historiques insuffisantes"
Cells(f, 15) = Cells(f, 14) * (J + 1) / J
Cells(f, 11).Interior.Color = RGB(255, 165, 0)
End If
Cells(f, 14).EntireColumn.Hidden = True
Cells(f, 15).EntireColumn.Hidden = True
Cells(f, 16) = Cells(f, 3) / (Cells(f, 15) / (J + 1))
Cells(f, 16).EntireColumn.Hidden = True
Cells(f, 11) = Cells(f, 16)
End Sub |
Partager