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 37 38 39 40 41 42 43 44 45 46 47 48 49
|
Option Explicit
Sub GenPlan(ByVal N As Long, K As Long)
Dim i As Long, x As Long, s As Long, j As Long
Cells.ClearContents
For i = 1 To N - 1
Cells(1, i).Value = 0
Next
Cells(1, N).Value = K
x = 1
Do
i = N
Do While Cells(x, i) = 0 And i > 1
i = i - 1
Loop
s = K - Sommer(x, 1, i - 1)
If Cells(x, i).Value = s Then
For j = i To N - 1
Cells(x + 1, j).Value = 0
Next
Cells(x + 1, N).Value = s - 1
Else
Cells(x + 1, i).Value = Cells(x, i).Value - 1
End If
Cells(x + 1, i - 1).Value = Cells(x, i - 1).Value + 1
i = i - 2
Do While i > 0
Cells(x + 1, i).Value = Cells(x, i).Value
i = i - 1
Loop
x = x + 1
Loop Until Cells(x, 1) = K
End Sub
Function Sommer(ByVal line, ByVal fc As Long, ByVal lc As Long) As Long
Dim s As Long, i As Long
s = 0
For i = fc To lc
s = s + Cells(line, i).Value
Next
Sommer = s
End Function
Sub Test_GenPlan()
Call GenPlan(4, 3)
End Sub
Tu n'a qu'à exécuter mettre en paramètre le nombre de Planning et d'individus dans la routine Test_GenPlan pour produire le tableau désiré. |
Partager