IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

tableau de nombres variables


Sujet :

Macros et VBA Excel

  1. #41
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    merci. En effet, ça fonctionne mieux en réinitialisant les valeurs de X.

    Maintenant j'aurais voulu éliminer toutes les combinaisons non rentables (où la journée d'un camion n'est pas optimisée).

    Si X42 (ou X43) <>0, on se concentre uniquement sur "TapresT42" (car le TapresT22 aura été optimisé lui). Je veux que les lignes où TapresT42 (ou T43)>T42 soit supprimer.

    Voici la macro que j'ai essayé de faire et qui ne donne rien:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Sub efface()
    Dim i As Long, T42 As Single
     
    T42 = [F1]
    For i = Range("A7").Row To Range("A65536").Row
    If Cells(i, "L").Value > T42 Then
    Rows(i).Delete
    End If
    Next i
     
     
    End Sub

    par contre si X42 (ou X43)=0, alors on se concentre uniquement sur "TapresT22" (ou T23). On élimine les lignes où TapresT22>T22

    il faut vraiment que j'arrive à supprimer un max de combinaisons.

    J'ai rassemblé dans une même macro le calcul de la condition de cubage et le calcul du nb de camions. Et il se trouve que je n'ai pas assez de lignes ds EXCEL.

    Donc en gros, avant de passer à la ligne suivante, il faudrait qu'à chaque fois, il vérifie les Tapres.

    je te joins uniquement la macro (le fichier est trop gros):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    Option Explicit 'indique les variables non déclarées
     
    Sub combinaison()
     
    Dim N22 As Integer, N42 As Integer, N23 As Integer, N43 As Integer, z22 As Integer, z42 As Integer, z23 As Integer, z43 As Integer, Z As Integer, w22 As Integer, w42 As Integer, w23 As Integer, w43 As Integer, W As Integer, A As Integer, Aa As Integer, Ab As Integer
    Dim T22 As Single, s22 As Single, T42 As Single, s42 As Single, T23 As Single, s23 As Single, T43 As Single, s43 As Single
    Dim X22 As Integer, X42 As Integer, X23 As Integer, X43 As Integer, Xtot2 As Integer, Xtot3 As Integer
    Dim maxi As Integer, Maxi2SF As Integer, Maxi2DF As Integer, Maxi3SF As Integer, Maxi3DF As Integer, MaxiT22 As Single, MaxiT23 As Single, TapresT22 As Single, TapresT42 As Single, TapresT23 As Single, TapresT43 As Single, TSFDF2 As Integer, TSFDF3 As Integer
    Dim Ligne As Long
     
     
    [A7.U65536].ClearContents
     
    Z = [A1] 'nb de tours max/jour/camion
    W = [A3] 'nb max camion/jour
    Ab = [C3] 'rdt/jour
    Aa = [C1] 'rdt limite/jour
    T22 = [E1]
    T42 = [E3]
    T23 = [G1]
    T43 = [G3]
    maxi = [E5] 'nb heures travaillées max
    Ligne = 7
     
    Maxi2SF = Int(maxi / T22) 'nb maxi de tours/camions/jour en SF(8m3)
    Maxi2DF = Int(maxi / T42) 'nb maxi de tours/camion/jour en DF (8)
    Maxi3SF = Int(maxi / T23) 'nb max de tour/cam/j en SF (10M3)
    Maxi3DF = Int(maxi / T43) 'nb max de tour/cam/j en DF(10)
     
     
    Do
     
    For z22 = 0 To Z
        For w22 = 0 To W
            For z42 = 0 To Z
                For w42 = 0 To W
                    For z23 = 0 To Z
                        For w23 = 0 To W
                            For z43 = 0 To Z
                                For w43 = 0 To W
     
    A = z22 * w22 * 8 + z42 * w42 * 8 + z23 * w23 * 10 + z43 * w43 * 10
     
    If z22 = 0 Xor w22 = 0 Then A = 0
    If z42 = 0 Xor w42 = 0 Then A = 0
    If z23 = 0 Xor w23 = 0 Then A = 0
    If z43 = 0 Xor w43 = 0 Then A = 0
     
     
     
    If Aa < A And A <= Ab Then
    Cells(Ligne, "A").Value = z22 * w22
    Cells(Ligne, "B").Value = z42 * w42
    Cells(Ligne, "C").Value = z23 * w23
    Cells(Ligne, "D").Value = z43 * w43
    Cells(Ligne, "E").Value = A
     
    N22 = z22 * w22
    N42 = z42 * w42
    N23 = z23 * w23
    N43 = z43 * w43
    Cells(Ligne, "G") = N22 * T22
    Cells(Ligne, "H") = N42 * T42
    Cells(Ligne, "O") = N23 * T23
    Cells(Ligne, "P") = N43 * T43
     
    s22 = N22 * T22
    s42 = N42 * T42
    s23 = N23 * T23
    s43 = N43 * T43
     
    'initialisation des valeurs de X
    X22 = 0
    X42 = 0
    X23 = 0
    X43 = 0
     
     
    'a) si N22=N42=0, on va à la ligne suivante
    If Not (N22 = 0 And N42 = 0) Then
     
     
        'on détermine le nombre de camions qu'il faut pour le simple fret
        'on cherche X22 tq Maxi*(X22-1)<=s22<=Maxi*X22
        If Int(N22 / Maxi2SF) < N22 / Maxi2SF Then X22 = Int(N22 / Maxi2SF) + 1 Else X22 = N22 / Maxi2SF
     
        'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
        MaxiT22 = X22 * maxi
     
        'tps libre du dernier camion de la flotte
        TapresT22 = (MaxiT22 - s22)
     
     
        'on détermine le nb de camions qu'il faut pour le double fret
        TSFDF2 = Int(TapresT22 / T42) 'nb de tours en DF du dernier camion de SF
     
        If N42 = 0 Then
            X42 = 0
        Else
            If Int((N42 - TSFDF2) / Maxi2DF) < ((N42 - TSFDF2) / Maxi2DF) Then X42 = Int((N42 - TSFDF2) / Maxi2DF) + 1 Else X42 = Int((N42 - TSFDF2) / Maxi2DF)
        End If
     
    End If
     
     
    If X42 <> 0 Then TapresT42 = ((X42 * Maxi2DF) - (N42 - TSFDF2)) * T42 Else TapresT42 = 0
     
    Xtot2 = X22 + X42
    [I1] = Maxi2SF
    [K1] = Maxi2DF
    Cells(Ligne, "I") = X22
    Cells(Ligne, "J") = TapresT22
    Cells(Ligne, "K") = X42
    Cells(Ligne, "L") = TapresT42
    Cells(Ligne, "M") = Xtot2
     
     
     
    'b) si N23=N43=0, on va à la ligne suivante
    If Not (N23 = 0 And N43 = 0) Then
     
     
        'on détermine le nombre de camions qu'il faut pour le simple fret
        'on cherche X23 tq Maxi*(X23-1)<=s23<=Maxi*X23
        If Int(N23 / Maxi3SF) < N23 / Maxi3SF Then X23 = Int(N23 / Maxi3SF) + 1 Else X23 = N23 / Maxi3SF
     
        'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
        MaxiT23 = X23 * maxi
     
        'tps libre du dernier camion de la flotte
        TapresT23 = (MaxiT23 - s23)
     
     
        'on détermine le nb de camions qu'il faut pour le double fret
        TSFDF3 = Int(TapresT23 / T43) 'nb de tours en DF du dernier camion de SF
        If N43 = 0 Then
            X43 = 0
        Else
            If Int((N43 - TSFDF3) / Maxi3DF) < ((N43 - TSFDF3) / Maxi3DF) Then X43 = Int((N43 - TSFDF3) / Maxi3DF) + 1 Else X43 = ((N43 - TSFDF3) / Maxi3DF)
            End If
     
     End If
     
    If X43 <> 0 Then TapresT43 = ((X43 * Maxi3DF) - (N43 - TSFDF3)) * T43 Else TapresT43 = 0
     
     
    Xtot3 = X23 + X43
    [I3] = Maxi3SF
    [K3] = Maxi3DF
    Cells(Ligne, "Q") = X23
    Cells(Ligne, "R") = TapresT23
    Cells(Ligne, "S") = X43
    Cells(Ligne, "T") = TapresT43
    Cells(Ligne, "U") = Xtot3
     
    Ligne = Ligne + 1
     
     
     
     
    End If
     
    Next
    Next
    Next
    Next
    Next
    Next
    Next
    Next
     
     
    Loop Until Ligne = 743 'jusqu'à la dernière lign
    End Sub


    en valeurs, les T st tjs les meme.
    Z=3
    W=4
    Ab=100
    Aa=92
    maxi=7h

    je voudrais écrire qqch ds ce genre, sauf que ça ne sécrie pas comme ça:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If TapresT42 < T42 And TapresT43 < T43 and (if X42=0 then TapresT22<T22) and (if X43=0 then TapresT23<T23)  Then Ligne = Ligne + 1
    en gros, la ligne ne doit pas exister si un ou plusieurs de ces 4 cas est vérifiés

    et avec le "loop until" il faut aller jusqu'à ce qu'il ait fait ttes les combinaisons vérifiant l'hypothèse de cubage.

    Parce qu'en regardant mieux les solutions qu'il me donne, il reprend plusieurs fois les même combinaisons.

  2. #42
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    Salut
    Alors déjà dommage que tu n'est pas continué les effort fait au niveau des indentations... bon passons

    Dans ton code tu utilises Xor, mais je suis pas certain que tu maitrise les résultat retournés? je me trompe?
    Voila le fonctionnement de Xor

    On pose
    si z22=0 est vrai on obtient True(on va dire 1), si l'égalité est fausse on obtient False (on va dire 0), idem pour w22

    Donc pour
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    (z22=0) Xor (w22=0) 'on obtient les combinaisons suivantes
    0 Xor 0 = 0
    0 Xor 1 = 1
    1 Xor 0 = 1
    1 Xor 1 = 0
    Je ne suis pas sur que ce dernier 0 soit voulu, si on applique ca a ton code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If z22 = 0 Xor w22 = 0 Then A = 0
    On aura A=0 uniquement si z22=0 ou w22=0 mais pas si z22=0 et w22=0.
    L'un ou l'autre mais pas les 2 en même temps.

    Pour avoir l'un ou l'autre ou les 2, il suffit d'utiliser Or a la place de Xor (le shérif de l'espace! ).
    Ainsi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    0 Or 0 = 0
    0 Or 1 = 1
    1 Or 0 = 1
    1 Or 1 = 1
    A++
    Qwaz

    Pour le "calcul" des possibilités, je ferais plutot un code comme ca

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    For w22 = 0 To W
        For w42 = 0 To W - w22
            For w23 = 0 To W - (w22 + w42)
                For w43 = 0 To W - (w22 + w42 + w23)
    Puisque le nombre de camion ne doit jamais dépasser W, inutile de faire des boucle qui donneront forcement un total de camion trop grand (w22+w42+w23+w43) si on raisonne a l'absurde quand tous les w auront pour valeur W on aura 4 fois trop de camion sur le chantier.

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  3. #43
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    oui c'est bien ce que je voulais dire. Je veux conserver les cas où ils sont tous les 2 nuls

  4. #44
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    slt,

    j'ai trouvé des incohérences dans ce que l'on a fait hier.

    En effet, j'ai testé le cas où W (le nb maxi de camions)=5 et le rendement Ab=100.
    J'ai ajouté une colonne aux tableaux qui calculent le prix total des camions PT=480*Xtot2 + 550*Xtot3

    première ligne: N22=0 N42=0 N23=10 N43=0, ça me donne Xtot3=2.
    PT=1100

    Après j'ai testé le cas où W=4, je m'attendais à retrouver le même cas et pourtant il n'y figure pas.

    je me demande si ça ne vient pas de la limitation à

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    For w22 = 1 To W
    For w42 = 1 To W - w22
    For w23 = 1 To W - (w22 + w42)
    For w43 = 1 To W - (w22 + w42 + w23)
    j'ai repris ça et je laisse aller tous les w jusque W.

    Mais mtnt j'ai pleins de lignes identiques donc inutiles qu'il faudrait que j'élimine.

    slt,

    j'ai fait des tests sur le dernier code que tu m'as donné hier et à chaque fois, il y avait qu'une seule ligne. Je comprenais pas pourquoi et en fait je me suis rendu compte que le Ligne=Ligne+1 avait sauté donc normal.

    voila le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    Option Explicit 'indique les variables non déclarées
     
    Sub combinaison()
     
    Dim N22 As Integer, N42 As Integer, N23 As Integer, N43 As Integer, N32 As Integer, N33 As Integer, z22 As Integer, z42 As Integer, z23 As Integer, z43 As Integer, z32 As Integer, z33 As Integer, w22 As Integer, w42 As Integer, w23 As Integer, w43 As Integer, w32 As Integer, w33 As Integer, W As Integer, A As Integer, Aa As Integer, Ab As Integer, B As Integer, Ba As Integer, Bb As Integer
    Dim T22 As Single, s22 As Single, T42 As Single, s42 As Single, T32 As Single, s32 As Single, T23 As Single, s23 As Single, T43 As Single, s43 As Single, T33 As Single, s33 As Single
    Dim X22 As Integer, X42 As Integer, X32 As Integer, X23 As Integer, X43 As Integer, X33 As Integer, Xtot2 As Integer, Xtot3 As Integer
    Dim maxi As Integer, Maxi22SF As Integer, Maxi42DF As Integer, Maxi23SF As Integer, Maxi43DF As Integer, Maxi32SF As Integer, Maxi33SF As Integer, MaxiT22 As Single, MaxiT23 As Single, TapresT22 As Single, TapresT42 As Single, TapresT23 As Single, TapresT43 As Single, TapresT32 As Single, TapresT33 As Single, TSFDF22 As Integer, TSFDF32 As Integer, TSFDF23 As Integer, TSFDF33 As Integer, TSFSF2232 As Integer, TSFSF2333 As Integer
    Dim Ligne As Long, PT As Integer
    Dim a22 As Integer, a42 As Integer, a23 As Integer, a43 As Integer, a32 As Integer, a33 As Integer
     
    'On stop le refraichissement pour eviter le scintillement et gagner en vitesse
    Application.ScreenUpdating = False
     
    [A7.AH65536].ClearContents
    [M1].ClearContents
    [O1].ClearContents
    [Q1].ClearContents
    [M3].ClearContents
    [O3].ClearContents
    [Q3].ClearContents
     
    W = [A3] 'nb max camion/jour
    Ab = [C3] 'rdt/jour en déblais
    Aa = [C1] 'rdt limite/jour en déblais
    Bb = [E3] 'rdt/jour en remblais
    Ba = [E1] 'rdt limite/jour en remblais
    T22 = [G1]
    T42 = [G3]
    T32 = [G5]
    T23 = [I1]
    T43 = [I3]
    T33 = [I5]
    maxi = [A5] 'nb heures travaillées max
    Ligne = 7
     
    Maxi22SF = Int(maxi / T22) 'nb maxi de tours/camions/jour en SF(8m3) déblais
    Maxi42DF = Int(maxi / T42) 'nb maxi de tours/camion/jour en DF (8) déblais/remblais
    Maxi23SF = Int(maxi / T23) 'nb max de tour/cam/j en SF (10M3) déblais
    Maxi43DF = Int(maxi / T43) 'nb max de tour/cam/j en DF(10) déblais/remblais
    Maxi32SF = Int(maxi / T32) 'nb maxi de tours/camions/jour en SF(8m3) remblais
    Maxi33SF = Int(maxi / T33) 'nb maxi de tours/camions/jour en SF(10m3) remblais
     
    'Il vaut mieux mettre ca ici plutot que de le repeter a chaque boucle
    [M1] = Maxi22SF
    [O1] = Maxi42DF
    [Q1] = Maxi32SF
    [M3] = Maxi23SF
    [O3] = Maxi43DF
    [Q3] = Maxi33SF
     
    For w22 = 0 To W
        For z22 = 1 To Maxi22SF
            For w42 = 0 To W - w22
                For z42 = 1 To Maxi42DF
                    For w32 = 0 To W - (w22 + w42)
                        For z32 = 1 To Maxi32SF
                            For w23 = 0 To W - (w22 + w42 + w32)
                                For z23 = 1 To Maxi23SF
                                    For w43 = 0 To W - (w22 + w42 + w32 + w23)
                                        For z43 = 1 To Maxi43DF
                                            For w33 = 0 To W - (w22 + w42 + w32 + w23 + w43)
                                                For z33 = 1 To Maxi33SF
     
                                                    A = z22 * w22 * 8 + z42 * w42 * 8 + z23 * w23 * 10 + z43 * w43 * 10
                                                    B = z32 * w32 * 8 + z42 * w42 * 8 + z33 * w33 * 10 + z43 * w43 * 10
     
                                                    If (Aa < A And A <= Ab) And (Ba < B And B <= Bb) Then
     
                                                        N22 = z22 * w22
                                                        N42 = z42 * w42
                                                        N23 = z23 * w23
                                                        N43 = z43 * w43
     
                                                        s22 = N22 * T22
                                                        s42 = N42 * T42
                                                        s23 = N23 * T23
                                                        s43 = N43 * T43
     
     
                                                        N32 = z32 * w32
                                                        N42 = z42 * w42
                                                        N33 = z33 * w33
                                                        N43 = z43 * w43
     
                                                        s32 = N32 * T32
                                                        s42 = N42 * T42
                                                        s33 = N33 * T33
                                                        s43 = N43 * T43
     
                                                        PT = Xtot2 * 480 + Xtot3 * 550 'prix total camions
     
                                                        'initialisation des valeurs de X
                                                        X22 = 0
                                                        X42 = 0
                                                        X23 = 0
                                                        X43 = 0
                                                        X32 = 0
                                                        X33 = 0
     
                                                        'initialisation des temps restants
                                                        TapresT22 = 0
                                                        TapresT42 = 0
                                                        TapresT32 = 0
                                                        TapresT23 = 0
                                                        TapresT43 = 0
                                                        TapresT33 = 0
     
     
     
                                                        'a) si N22=N42=N32=0, on va à la ligne suivante
                                                        If Not (N22 = 0 And N42 = 0 And N32 = 0) Then
     
     
                                                            'on détermine le nombre de camions qu'il faut pour le simple fret déblais
                                                            'on cherche X22 tq Maxi*(X22-1)<=s22<=Maxi*X22
                                                            If Int(N22 / Maxi22SF) < N22 / Maxi22SF Then X22 = Int(N22 / Maxi22SF) + 1 Else X22 = N22 / Maxi22SF
     
                                                            'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                            MaxiT22 = X22 * maxi
     
                                                            'tps libre du dernier camion de la flotte
                                                            TapresT22 = (MaxiT22 - s22)
     
                                                            'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                            If T22 <= TapresT22 And TapresT22 < T42 Then Exit For
     
                                                            'on détermine le nb de camions qu'il faut pour le double fret
                                                            TSFDF22 = Int(TapresT22 / T42) 'nb de tours en DF du dernier camion de SF
     
                                                            'on détermine le nb de camions qu'il faut pour le simple fret remblais
                                                            TSFSF2232 = Int(TapresT22 / T32) 'nb de tours en SF r du dernier camion en SF d
     
                                                            If N42 = 0 Then
                                                                X42 = 0
                                                                If Int((N32 - TSFSF2232) / Maxi32SF) < ((N32 - TSFSF2232) / Maxi32SF) Then X32 = Int((N32 - TSFSF2232) / Maxi32SF) + 1 Else X32 = Int((N32 - TSFSF2232) / Maxi32SF)
                                                            Else
                                                                If Int((N42 - TSFDF22) / Maxi42DF) < ((N42 - TSFDF22) / Maxi42DF) Then X42 = Int((N42 - TSFDF22) / Maxi42DF) + 1 Else X42 = Int((N42 - TSFDF22) / Maxi42DF)
                                                            End If
     
                                                            If X32 <> 0 Then TapresT32 = ((X32 * Maxi32SF) - (N32 - TSFSF2232)) * T32 Else TapresT32 = 0
     
                                                            If X42 <> 0 Then TapresT42 = ((X42 * Maxi42DF) - (N42 - TSFDF22)) * T42 Else TapresT42 = 0
     
                                                            'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                            If T42 <= TapresT42 And TapresT42 < T32 Then Exit For
     
     
                                                            'on détermine le nb de camions qu'il faut pour le simple fret remblais
                                                            TSFDF32 = Int(TapresT42 / T32) 'nb de tours en SF r du dernier camion de DF
     
                                                            If N32 = 0 Then
                                                                X32 = 0
                                                            Else
                                                                If Int((N32 - TSFDF32) / Maxi32SF) < ((N32 - TSFDF32) / Maxi32SF) Then X32 = Int((N32 - TSFDF32) / Maxi32SF) + 1 Else X32 = Int((N32 - TSFDF32) / Maxi32SF)
                                                            End If
                                                        End If
     
                                                        If X32 <> 0 Then TapresT32 = ((X32 * Maxi32SF) - (N32 - TSFDF32)) * T32 Else TapresT32 = 0
                                                        'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                        If T32 <= TapresT32 Then Exit For
     
     
     
                                                        'b) si N23=N43=N33=0, on va à la ligne suivante
                                                        If Not (N23 = 0 And N43 = 0 And N33 = 0) Then
     
     
                                                            'on détermine le nombre de camions qu'il faut pour le simple fret déblais
                                                            'on cherche X23 tq Maxi*(X23-1)<=s23<=Maxi*X23
                                                            If Int(N23 / Maxi23SF) < N23 / Maxi23SF Then X23 = Int(N23 / Maxi23SF) + 1 Else X23 = N23 / Maxi23SF
     
                                                            'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                            MaxiT23 = X23 * maxi
     
                                                            'tps libre du dernier camion de la flotte
                                                            TapresT23 = (MaxiT23 - s23)
     
                                                            'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                            If T23 <= TapresT23 And TapresT23 < T43 Then Exit For
     
                                                            'on détermine le nb de camions qu'il faut pour le double fret
                                                            TSFDF23 = Int(TapresT23 / T43) 'nb de tours en DF du dernier camion de SF
     
                                                            TSFSF2333 = Int(TapresT23 / T33) 'nb de tours en SF r du dernier camion de SF d
     
                                                            If N43 = 0 Then
                                                                X43 = 0
                                                                If Int((N33 - TSFSF2333) / Maxi33SF) < ((N33 - TSFSF2333) / Maxi33SF) Then X33 = Int((N33 - TSFSF2333) / Maxi33SF) + 1 Else X33 = Int((N33 - TSFSF2333) / Maxi33SF)
                                                            Else
                                                                If Int((N43 - TSFDF23) / Maxi43DF) < ((N43 - TSFDF23) / Maxi43DF) Then X43 = Int((N43 - TSFDF23) / Maxi43DF) + 1 Else X43 = ((N43 - TSFDF23) / Maxi43DF)
                                                            End If
                                                            If X33 <> 0 Then TapresT33 = ((X33 * Maxi33SF) - (N33 - TSFSF2333)) * T33 Else TapresT33 = 0
                                                            If X43 <> 0 Then TapresT43 = ((X43 * Maxi43DF) - (N43 - TSFDF23)) * T43 Else TapresT43 = 0
     
     
                                                            'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                            If T43 <= TapresT43 And TapresT43 < T33 Then Exit For
     
                                                            'on détermine le nb de camions qu'il faut pour le simple fret remblais
                                                            TSFDF33 = Int(TapresT43 / T33) 'nb de tours en SF r du dernier camion de DF
     
                                                            If N33 = 0 Then
                                                                X33 = 0
                                                            Else
                                                                If Int((N33 - TSFDF33) / Maxi33SF) < ((N33 - TSFDF33) / Maxi33SF) Then X33 = Int((N33 - TSFDF33) / Maxi33SF) + 1 Else X33 = Int((N33 - TSFDF33) / Maxi33SF)
     
                                                            End If
     
                                                        End If
     
                                                        If X33 <> 0 Then TapresT33 = ((X33 * Maxi33SF) - (N33 - TSFDF33)) * T33 Else TapresT33 = 0
                                                        'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                        If T33 <= TapresT33 Then Exit For
     
                                                        'Si le code arrive ici c'est que notre flotte est bien occupé, donc on note les résultats dans le tableau
     
                                                        Cells(Ligne, "A").Value = z22 * w22
                                                        Cells(Ligne, "B").Value = z42 * w42
                                                        Cells(Ligne, "C").Value = z32 * w32
                                                        Cells(Ligne, "D").Value = z23 * w23
                                                        Cells(Ligne, "E").Value = z43 * w43
                                                        Cells(Ligne, "F").Value = z33 * w33
                                                        Cells(Ligne, "G").Value = A
                                                        Cells(Ligne, "H").Value = B
     
     
                                                        Cells(Ligne, "K") = N22 * T22
                                                        Cells(Ligne, "L") = N42 * T42
                                                        Cells(Ligne, "M") = N32 * T32
                                                        Cells(Ligne, "V") = N23 * T23
                                                        Cells(Ligne, "W") = N43 * T43
                                                        Cells(Ligne, "X") = N33 * T33
     
                                                        'Xtot2 = X22 + X42 + X32
                                                        Cells(Ligne, "N") = X22
                                                        Cells(Ligne, "O") = TapresT22
                                                        Cells(Ligne, "P") = X42
                                                        Cells(Ligne, "Q") = TapresT42
                                                        Cells(Ligne, "R") = X32
                                                        Cells(Ligne, "S") = TapresT32
                                                        Cells(Ligne, "T") = X22 + X42 + X32 'Xtot2
     
     
                                                        'Xtot3 = X23 + X43 + X33
                                                        Cells(Ligne, "Y") = X23
                                                        Cells(Ligne, "Z") = TapresT23
                                                        Cells(Ligne, "AA") = X43
                                                        Cells(Ligne, "AB") = TapresT43
                                                        Cells(Ligne, "AC") = X33
                                                        Cells(Ligne, "AD") = TapresT33
                                                        Cells(Ligne, "AE") = X23 + X43 + X33 'Xtot3
     
                                                        Cells(Ligne, "AH") = (X22 + X42 + X32) * 480 + (X23 + X43 + X33) * 550
     
                                                        'If X22 + X42 + X32 + X23 + X43 + X43 <= W Then Ligne = Ligne + 1 'pas besoin c pris en compte dans les boucles For
                                                        Ligne = Ligne + 1
     
                                                    End If
     
                                                Next
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
    Next
     
    End Sub
    je te redonne la trame. http://cjoint.com/?epqMGASk02
    quand tu testeras, tu verras il y a énormément de doublons. Donc au final, je pense qu'il restera pas forcément bcp de lignes.

    Quelqu'un m'a passé ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    Option Explicit
    Sub es()
           Dim t As Variant, t2() As String, m As Object, x As Long, i As Long, k As Long
           On Error Resume Next
           Application.ScreenUpdating = False
           Set m = CreateObject("Scripting.Dictionary")
           t = Range("a7:v" & Cells.Find("*", , , , , xlPrevious).Row)
           x = 1
           For i = LBound(t) To UBound(t)
           t(i, 22) = t(i, 1) & t(i, 2) & t(i, 3) & t(i, 4) & t(i, 5) & t(i, 6) & t(i, 7) & t(i, 8) & t(i, 9) & t(i, 10) _
           & t(i, 11) & t(i, 12) & t(i, 13) & t(i, 14) & t(i, 15) & t(i, 16) & t(i, 17) & t(i, 18) & t(i, 19) & t(i, 20) & t(i, 21)
           If Not m.Exists(t(i, 22)) Then
           m.Add t(i, 22), t(i, 22)
           ReDim Preserve t2(1 To 21, 1 To x)
           For k = 1 To 21: t2(k, x) = t(i, k): Next k: x = x + 1:  End If: Next i
           Range("a7:u" & Cells.Find("*", , , , , xlPrevious).Row).ClearContents
           Range("a7").Resize(UBound(t2, 2), UBound(t2, 1)) = Application.Transpose(t2)
           Erase t, t2: Set m = Nothing
    End Sub
    il était pour la trame précédente, quand il y avait encore pas de remblais. Normalement il doit supprimer les doublons.
    Pourtant j'ai pas réussi à le faire fonctionner.



    J'ai un autre souci. J'avais trouvé sur excel download des fichiers qui permettent de calculer les distances entre ville.
    D'abord celui-la qui est super mais codé:http://cjoint.com/?epqSdeB24P

    et celui-ci (non codé):http://cjoint.com/?epqS6RWIeh
    avec celui-ci j'ai 2 pbs:
    1) quand je rentre énormément de distance à calculer, au bout d'un moment il me met pour tte itinéraire non trouvée alors que parfois il a calculé la distance plus haut ds le tableau.

    2) ou alors il bug et souligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    .Refresh BackgroundQuery:=False 'je ne sais pas pourquoi, mais cette ligne bugue régulièrement, soit dès le début si je n'ai pas mis un coup de CCleaner avant, ou vers la 30ème ligne
    si tu savais d'ou ça venait ça pourrait m'etre tres utile

  5. #45
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    Salut
    Citation Envoyé par Emma95
    en fait je me suis rendu compte que le Ligne=Ligne+1 avait sauté donc normal.
    En effet c'est moi qui avais désactive la ligne de code puisque la condition était déjà réalisée par la modification des boucle For ... mais je n'ai pas pensé a déplacer l'incrémentation de "Ligne".

    Citation Envoyé par Emma95
    Quelqu'un m'a passé ce code
    Oui j'avais vu ton autre poste, c'est une contribution de l'amie Leti. Je pense que dans un 1er temps il serait bien de trouver pourquoi il y a des doublon et de mettre les conditions nécessaire a leur non apparition, plutôt que de les supprimer par la suite.
    Il serait aussi possible de simplement regarder dans le tableau ce qui existe déjà, mais ça risque d'être gourmand en ressource.

    Pour ce qui est des autre prog, j'essaierai de prendre 5 min pour y jeter un oeil, mais le mieux serait d'ouvrir un nouveau sujet je pense.

    Peut être a plus
    Qwaz

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  6. #46
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    c'est clair le mieux c'est de regarder si la ligne i+1 est identique à la ligne i et si c'est le cas de la supprimer

  7. #47
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    As tu bien regardé si une fois les doublon supprimé tu obtenais bien des résultats cohérents et s'il ne manquer pas des solutions (au moins des solutions intéressantes qui seraient passée a travers).
    Si tu veux je serais sur le Chat.
    ++

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  8. #48
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    je peux pas rester ce soir.

    Mais à part les doublons, les solutions sont corrects et le nb de camions optimisé.

    mais j'aimerais pouvoir éliminer tous les doublons avant de commencer à rajouter plusieur remblais.

  9. #49
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    Voila qui devrait convenir

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    Option Explicit 'indique les variables non déclarées
     
    Sub combinaison()
     
    Dim N22 As Integer, N42 As Integer, N23 As Integer, N43 As Integer, N32 As Integer, N33 As Integer, z22 As Integer, z42 As Integer, z23 As Integer, z43 As Integer, z32 As Integer, z33 As Integer, w22 As Integer, w42 As Integer, w23 As Integer, w43 As Integer, w32 As Integer, w33 As Integer, W As Integer, A As Integer, Aa As Integer, Ab As Integer, B As Integer, Ba As Integer, Bb As Integer
    Dim T22 As Single, s22 As Single, T42 As Single, s42 As Single, T32 As Single, s32 As Single, T23 As Single, s23 As Single, T43 As Single, s43 As Single, T33 As Single, s33 As Single
    Dim X22 As Integer, X42 As Integer, X32 As Integer, X23 As Integer, X43 As Integer, X33 As Integer, Xtot2 As Integer, Xtot3 As Integer
    Dim maxi As Integer, Maxi22SF As Integer, Maxi42DF As Integer, Maxi23SF As Integer, Maxi43DF As Integer, Maxi32SF As Integer, Maxi33SF As Integer, MaxiT22 As Single, MaxiT23 As Single, TapresT22 As Single, TapresT42 As Single, TapresT23 As Single, TapresT43 As Single, TapresT32 As Single, TapresT33 As Single, TSFDF22 As Integer, TSFDF32 As Integer, TSFDF23 As Integer, TSFDF33 As Integer, TSFSF2232 As Integer, TSFSF2333 As Integer
    Dim Ligne As Long, PT As Integer
    Dim a22 As Integer, a42 As Integer, a23 As Integer, a43 As Integer, a32 As Integer, a33 As Integer
    Dim DicoAntiDoublon As New Dictionary, StrAntiDoublon As String
     
    'On stop le refraichissement pour eviter le scintillement et gagner en vitesse
    Application.ScreenUpdating = False
     
    [A7.AH65536].ClearContents
    [M1].ClearContents
    [O1].ClearContents
    [Q1].ClearContents
    [M3].ClearContents
    [O3].ClearContents
    [Q3].ClearContents
     
    W = [A3] 'nb max camion/jour
    Ab = [C3] 'rdt/jour en déblais
    Aa = [C1] 'rdt limite/jour en déblais
    Bb = [E3] 'rdt/jour en remblais
    Ba = [E1] 'rdt limite/jour en remblais
    T22 = [G1]
    T42 = [G3]
    T32 = [G5]
    T23 = [I1]
    T43 = [I3]
    T33 = [I5]
    maxi = [A5] 'nb heures travaillées max
    Ligne = 7
     
    Maxi22SF = Int(maxi / T22) 'nb maxi de tours/camions/jour en SF(8m3) déblais
    Maxi42DF = Int(maxi / T42) 'nb maxi de tours/camion/jour en DF (8) déblais/remblais
    Maxi23SF = Int(maxi / T23) 'nb max de tour/cam/j en SF (10M3) déblais
    Maxi43DF = Int(maxi / T43) 'nb max de tour/cam/j en DF(10) déblais/remblais
    Maxi32SF = Int(maxi / T32) 'nb maxi de tours/camions/jour en SF(8m3) remblais
    Maxi33SF = Int(maxi / T33) 'nb maxi de tours/camions/jour en SF(10m3) remblais
     
    'Il vaut mieux mettre ca ici plutot que de le repeter a chaque boucle
    [M1] = Maxi22SF
    [O1] = Maxi42DF
    [Q1] = Maxi32SF
    [M3] = Maxi23SF
    [O3] = Maxi43DF
    [Q3] = Maxi33SF
     
    For w22 = 0 To W
        For z22 = 1 To Maxi22SF
            For w42 = 0 To W - w22
                For z42 = 1 To Maxi42DF
                    For w32 = 0 To W - (w22 + w42)
                        For z32 = 1 To Maxi32SF
                            For w23 = 0 To W - (w22 + w42 + w32)
                                For z23 = 1 To Maxi23SF
                                    For w43 = 0 To W - (w22 + w42 + w32 + w23)
                                        For z43 = 1 To Maxi43DF
                                            For w33 = 0 To W - (w22 + w42 + w32 + w23 + w43)
                                                For z33 = 1 To Maxi33SF
     
                                                    A = z22 * w22 * 8 + z42 * w42 * 8 + z23 * w23 * 10 + z43 * w43 * 10
                                                    B = z32 * w32 * 8 + z42 * w42 * 8 + z33 * w33 * 10 + z43 * w43 * 10
     
                                                    If (Aa < A And A <= Ab) And (Ba < B And B <= Bb) Then
     
                                                        'Si les resultats des N sont les mêmes on quite
     
                                                        N22 = z22 * w22
                                                        N42 = z42 * w42
                                                        N23 = z23 * w23
                                                        N43 = z43 * w43
                                                        N32 = z32 * w32
                                                        N33 = z33 * w33
     
                                                        'N42 = z42 * w42 'deja fait
                                                        'N43 = z43 * w43
     
                                                        s22 = N22 * T22
                                                        s42 = N42 * T42
                                                        s23 = N23 * T23
                                                        s43 = N43 * T43
                                                        s32 = N32 * T32
                                                        s33 = N33 * T33
     
                                                        's42 = N42 * T42 'deja fait
                                                        's43 = N43 * T43
     
                                                        'PT n'est utilisé null part, et il serait bizard de le calculer ici, avec des valeur de tot2 et tot3 correspondant a la ligne du dessus
                                                        'PT = Xtot2 * 480 + Xtot3 * 550 'prix total camions
     
                                                        'initialisation des valeurs de X
                                                        X22 = 0
                                                        X42 = 0
                                                        X23 = 0
                                                        X43 = 0
                                                        X32 = 0
                                                        X33 = 0
     
                                                        'initialisation des temps restants
                                                        TapresT22 = 0
                                                        TapresT42 = 0
                                                        TapresT32 = 0
                                                        TapresT23 = 0
                                                        TapresT43 = 0
                                                        TapresT33 = 0
     
     
     
                                                        'a) si N22=N42=N32=0, on va à la ligne suivante
                                                        If Not (N22 = 0 And N42 = 0 And N32 = 0) Then
     
     
                                                            'on détermine le nombre de camions qu'il faut pour le simple fret déblais
                                                            'on cherche X22 tq Maxi*(X22-1)<=s22<=Maxi*X22
                                                            If Int(N22 / Maxi22SF) < N22 / Maxi22SF Then X22 = Int(N22 / Maxi22SF) + 1 Else X22 = N22 / Maxi22SF
     
                                                            'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                            MaxiT22 = X22 * maxi
     
                                                            'tps libre du dernier camion de la flotte
                                                            TapresT22 = (MaxiT22 - s22)
     
                                                            'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                            If T22 <= TapresT22 And TapresT22 < T42 Then GoTo Suite
     
                                                            'on détermine le nb de camions qu'il faut pour le double fret
                                                            TSFDF22 = Int(TapresT22 / T42) 'nb de tours en DF du dernier camion de SF
     
                                                            'on détermine le nb de camions qu'il faut pour le simple fret remblais
                                                            TSFSF2232 = Int(TapresT22 / T32) 'nb de tours en SF r du dernier camion en SF d
     
                                                            If N42 = 0 Then
                                                                X42 = 0
                                                                If Int((N32 - TSFSF2232) / Maxi32SF) < ((N32 - TSFSF2232) / Maxi32SF) Then X32 = Int((N32 - TSFSF2232) / Maxi32SF) + 1 Else X32 = Int((N32 - TSFSF2232) / Maxi32SF)
                                                            Else
                                                                If Int((N42 - TSFDF22) / Maxi42DF) < ((N42 - TSFDF22) / Maxi42DF) Then X42 = Int((N42 - TSFDF22) / Maxi42DF) + 1 Else X42 = Int((N42 - TSFDF22) / Maxi42DF)
                                                            End If
     
                                                            If X32 <> 0 Then TapresT32 = ((X32 * Maxi32SF) - (N32 - TSFSF2232)) * T32 Else TapresT32 = 0
     
                                                            If X42 <> 0 Then TapresT42 = ((X42 * Maxi42DF) - (N42 - TSFDF22)) * T42 Else TapresT42 = 0
     
                                                            'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                            If T42 <= TapresT42 And TapresT42 < T32 Then GoTo Suite
     
     
                                                            'on détermine le nb de camions qu'il faut pour le simple fret remblais
                                                            TSFDF32 = Int(TapresT42 / T32) 'nb de tours en SF r du dernier camion de DF
     
                                                            If N32 = 0 Then
                                                                X32 = 0
                                                            Else
                                                                If Int((N32 - TSFDF32) / Maxi32SF) < ((N32 - TSFDF32) / Maxi32SF) Then X32 = Int((N32 - TSFDF32) / Maxi32SF) + 1 Else X32 = Int((N32 - TSFDF32) / Maxi32SF)
                                                            End If
                                                        End If
     
                                                        If X32 <> 0 Then TapresT32 = ((X32 * Maxi32SF) - (N32 - TSFDF32)) * T32 Else TapresT32 = 0
                                                        'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                        If T32 <= TapresT32 Then GoTo Suite
     
     
     
                                                        'b) si N23=N43=N33=0, on va à la ligne suivante
                                                        If Not (N23 = 0 And N43 = 0 And N33 = 0) Then
     
     
                                                            'on détermine le nombre de camions qu'il faut pour le simple fret déblais
                                                            'on cherche X23 tq Maxi*(X23-1)<=s23<=Maxi*X23
                                                            If Int(N23 / Maxi23SF) < N23 / Maxi23SF Then X23 = Int(N23 / Maxi23SF) + 1 Else X23 = N23 / Maxi23SF
     
                                                            'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                            MaxiT23 = X23 * maxi
     
                                                            'tps libre du dernier camion de la flotte
                                                            TapresT23 = (MaxiT23 - s23)
     
                                                            'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                            If T23 <= TapresT23 And TapresT23 < T43 Then GoTo Suite
     
                                                            'on détermine le nb de camions qu'il faut pour le double fret
                                                            TSFDF23 = Int(TapresT23 / T43) 'nb de tours en DF du dernier camion de SF
     
                                                            TSFSF2333 = Int(TapresT23 / T33) 'nb de tours en SF r du dernier camion de SF d
     
                                                            If N43 = 0 Then
                                                                X43 = 0
                                                                If Int((N33 - TSFSF2333) / Maxi33SF) < ((N33 - TSFSF2333) / Maxi33SF) Then X33 = Int((N33 - TSFSF2333) / Maxi33SF) + 1 Else X33 = Int((N33 - TSFSF2333) / Maxi33SF)
                                                            Else
                                                                If Int((N43 - TSFDF23) / Maxi43DF) < ((N43 - TSFDF23) / Maxi43DF) Then X43 = Int((N43 - TSFDF23) / Maxi43DF) + 1 Else X43 = ((N43 - TSFDF23) / Maxi43DF)
                                                            End If
                                                            If X33 <> 0 Then TapresT33 = ((X33 * Maxi33SF) - (N33 - TSFSF2333)) * T33 Else TapresT33 = 0
                                                            If X43 <> 0 Then TapresT43 = ((X43 * Maxi43DF) - (N43 - TSFDF23)) * T43 Else TapresT43 = 0
     
     
                                                            'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                            If T43 <= TapresT43 And TapresT43 < T33 Then GoTo Suite
     
                                                            'on détermine le nb de camions qu'il faut pour le simple fret remblais
                                                            TSFDF33 = Int(TapresT43 / T33) 'nb de tours en SF r du dernier camion de DF
     
                                                            If N33 = 0 Then
                                                                X33 = 0
                                                            Else
                                                                If Int((N33 - TSFDF33) / Maxi33SF) < ((N33 - TSFDF33) / Maxi33SF) Then X33 = Int((N33 - TSFDF33) / Maxi33SF) + 1 Else X33 = Int((N33 - TSFDF33) / Maxi33SF)
     
                                                            End If
     
                                                        End If
     
                                                        If X33 <> 0 Then TapresT33 = ((X33 * Maxi33SF) - (N33 - TSFDF33)) * T33 Else TapresT33 = 0
                                                        'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                        If T33 <= TapresT33 Then GoTo Suite
     
     
                                                        'On verifie que cette solution n'est pas deja presente
                                                        Xtot2 = X22 + X42 + X32
                                                        Xtot3 = X23 + X43 + X33
                                                        'On regroupe toutes les infos qui caracterise la ligne, les N, A et B, XTot2 et XTot3
                                                        StrAntiDoublon = CStr(N22) & "-" & CStr(N42) & "-" & CStr(N23) & "-" & CStr(N43) & "-" & CStr(N32) & "-" & CStr(N33) & "-" & CStr(A) & "-" & CStr(B) & "-" & CStr(Xtot2) & "-" & CStr(Xtot3)
                                                        'On regarde si c'est info existent deja
                                                        If DicoAntiDoublon.Exists(StrAntiDoublon) Then GoTo Suite
                                                        'On les rajoute puisqu'elles ne figurent pas dans le dico
                                                        DicoAntiDoublon.Add StrAntiDoublon, 0
     
     
                                                        'Si le code arrive ici c'est que notre flotte est bien occupé, donc on note les résultats dans le tableau
     
                                                        Cells(Ligne, "A").Value = z22 * w22
                                                        Cells(Ligne, "B").Value = z42 * w42
                                                        Cells(Ligne, "C").Value = z32 * w32
                                                        Cells(Ligne, "D").Value = z23 * w23
                                                        Cells(Ligne, "E").Value = z43 * w43
                                                        Cells(Ligne, "F").Value = z33 * w33
                                                        Cells(Ligne, "G").Value = A
                                                        Cells(Ligne, "H").Value = B
     
     
                                                        Cells(Ligne, "K") = N22 * T22
                                                        Cells(Ligne, "L") = N42 * T42
                                                        Cells(Ligne, "M") = N32 * T32
                                                        Cells(Ligne, "V") = N23 * T23
                                                        Cells(Ligne, "W") = N43 * T43
                                                        Cells(Ligne, "X") = N33 * T33
     
                                                        Cells(Ligne, "N") = X22
                                                        Cells(Ligne, "O") = TapresT22
                                                        Cells(Ligne, "P") = X42
                                                        Cells(Ligne, "Q") = TapresT42
                                                        Cells(Ligne, "R") = X32
                                                        Cells(Ligne, "S") = TapresT32
                                                        Cells(Ligne, "T") = Xtot2
     
     
                                                        Cells(Ligne, "Y") = X23
                                                        Cells(Ligne, "Z") = TapresT23
                                                        Cells(Ligne, "AA") = X43
                                                        Cells(Ligne, "AB") = TapresT43
                                                        Cells(Ligne, "AC") = X33
                                                        Cells(Ligne, "AD") = TapresT33
                                                        Cells(Ligne, "AE") = Xtot3
     
                                                        Cells(Ligne, "AH") = (X22 + X42 + X32) * 480 + (X23 + X43 + X33) * 550
     
                                                        'If X22 + X42 + X32 + X23 + X43 + X43 <= W Then Ligne = Ligne + 1 'pas besoin c pris en compte dans les boucles For
                                                        Ligne = Ligne + 1
     
                                                    End If
    Suite:
                                                Next
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
    Next
     
    DicoAntiDoublon.RemoveAll
    Set DicoAntiDoublon = Nothing
    Application.ScreenUpdating = True
    End Sub
    Pour que ce code fonctionne tu dois faire une petit manip dans VBA
    Dans le menu Outil -> Références... -> Tu cherches et tu coches dans la liste, "Microsoft scripting runtime", c'est pour permettre l'utilisation du dictionary.

    Petit plus dans une de tes cellules en haut tu mets cette formule, tu aura ainsi le somme la plus basse qui existe dans le tableau
    A++
    Qwaz

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  10. #50
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    salut,

    je suis repartie de ton dernier fichier (où on supprimait les doublons) pour m'intéresser à deux choses:

    1) passer à 4 camions (6m3, 8m3, 10m3, 12m3). Quand je lance la macro ça cherche indéfiniment. Est-ce que c'est normal ou pas?
    voici la macro:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    Option Explicit 'indique les variables non déclarées
     
    Sub combinaison()
     
    Dim N21 As Integer, N41 As Integer, N31 As Integer, N22 As Integer, N42 As Integer, N32 As Integer, N23 As Integer, N43 As Integer, N33 As Integer, N24 As Integer, N44 As Integer, N34 As Integer, z21 As Integer, z41 As Integer, z31 As Integer, z22 As Integer, z42 As Integer, z32 As Integer, z23 As Integer, z43 As Integer, z33 As Integer, z24 As Integer, z44 As Integer, z34 As Integer, w21 As Integer, w41 As Integer, w31 As Integer, w22 As Integer, w42 As Integer, w32 As Integer, w23 As Integer, w43 As Integer, w33 As Integer, w24 As Integer, w44 As Integer, w34 As Integer, W As Integer, A As Integer, Aa As Integer, Ab As Integer, Ba As Integer, Bb As Integer, B As Integer
    Dim T21 As Single, s21 As Single, T41 As Single, s41 As Single, T31 As Single, s31 As Single, T22 As Single, s22 As Single, T42 As Single, s42 As Single, T32 As Single, s32 As Single, T23 As Single, s23 As Single, T43 As Single, s43 As Single, T33 As Single, s33 As Single, T24 As Single, s24 As Single, T44 As Single, s44 As Single, T34 As Single, s34 As Single
    Dim X21 As Integer, X41 As Integer, X31 As Integer, X22 As Integer, X42 As Integer, X32 As Integer, X23 As Integer, X43 As Integer, X33 As Integer, X24 As Integer, X44 As Integer, X34 As Integer, Xtot1 As Integer, Xtot2 As Integer, Xtot3 As Integer, Xtot4 As Integer
    Dim maxi As Integer, Maxi21SF As Integer, Maxi41DF As Integer, Maxi31SF As Integer, Maxi22SF As Integer, Maxi42DF As Integer, Maxi32SF As Integer, Maxi23SF As Integer, Maxi43DF As Integer, Maxi33SF, Maxi24SF As Integer, Maxi44DF As Integer, Maxi34SF, MaxiT21 As Single, MaxiT22 As Single, MaxiT23 As Single, MaxiT24 As Single, TapresT21 As Single, TapresT41 As Single, TapresT31 As Single, TapresT22 As Single, TapresT42 As Single, TapresT32 As Single, TapresT23 As Single, TapresT43 As Single, TapresT33 As Single, TapresT24 As Single, TapresT44 As Single, TapresT34 As Single, TSFDF21 As Integer, TSFDF31 As Integer, TSFDF22 As Integer, TSFDF32 As Integer, TSFDF23 As Integer, TSFDF33 As Integer, TSFDF24 As Integer, TSFDF34 As Integer, TSFSF2131 As Integer, TSFSF2232 As Integer, TSFSF2333 As Integer, TSFSF2434 As Integer
    Dim Ligne As Long, PT As Integer
    Dim a21 As Integer, a41 As Integer, a31 As Integer, a22 As Integer, a42 As Integer, a32 As Integer, a23 As Integer, a43 As Integer, a33 As Integer, a24 As Integer, a44 As Integer, a34 As Integer
    Dim DicoAntiDoublon As New Dictionary, StrAntiDoublon As String
     
    'On stop le refraichissement pour eviter le scintillement et gagner en vitesse
    Application.ScreenUpdating = False
     
    [A7.BF65536].ClearContents
    [S1].ClearContents
    [S2].ClearContents
    [S3].ClearContents
    [S4].ClearContents
    [U1].ClearContents
    [U2].ClearContents
    [U3].ClearContents
    [U4].ClearContents
    [W1].ClearContents
    [W2].ClearContents
    [W3].ClearContents
    [W4].ClearContents
     
     
    W = [A3] 'nb max camion/jour
    Ab = [C3] 'rdt/jour déblais
    Aa = [C1] 'rdt limite/jour déblais
    Ba = [E1] 'rdt limite/jour remblais
    Bb = [E3] 'rdt/jour remblais
    T21 = [G1]
    T41 = [G3]
    T31 = [G5]
    T22 = [J1]
    T42 = [J3]
    T32 = [J5]
    T23 = [M1]
    T43 = [M3]
    T33 = [M5]
    T24 = [P1]
    T44 = [P3]
    T34 = [P5]
    maxi = [A5] 'nb heures travaillées max
    Ligne = 7
     
    Maxi21SF = Int(maxi / T21) 'nb maxi de tours/camions/jour en SF déblais(6m3)
    Maxi41DF = Int(maxi / T41) 'nb maxi de tours/camion/jour en DF (6)
    Maxi31SF = Int(maxi / T31) 'nb maxi de tours/camions/jour en SF remblais(6m3)
    Maxi22SF = Int(maxi / T22) 'nb maxi de tours/camions/jour en SF déblais(8m3)
    Maxi42DF = Int(maxi / T42) 'nb maxi de tours/camion/jour en DF (8)
    Maxi32SF = Int(maxi / T32) 'nb maxi de tours/camions/jour en SF remblais(8m3)
    Maxi23SF = Int(maxi / T23) 'nb max de tour/cam/j en SF déblais(10M3)
    Maxi43DF = Int(maxi / T43) 'nb max de tour/cam/j en DF(10)
    Maxi33SF = Int(maxi / T33) 'nb max de tour/cam/j en SF remblais(10M3)
    Maxi24SF = Int(maxi / T24) 'nb maxi de tours/camions/jour en SF déblais(12m3)
    Maxi44DF = Int(maxi / T44) 'nb maxi de tours/camion/jour en DF (12)
    Maxi34SF = Int(maxi / T34) 'nb maxi de tours/camions/jour en SF remblais(12m3)
     
    'Il vaut mieux mettre ca ici plutot que de le repeter a chaque boucle
    [S1] = Maxi21SF
    [U1] = Maxi41DF
    [W1] = Maxi31SF
    [S2] = Maxi22SF
    [U2] = Maxi42DF
    [W2] = Maxi32SF
    [S3] = Maxi23SF
    [U3] = Maxi43DF
    [W3] = Maxi33SF
    [S4] = Maxi24SF
    [U4] = Maxi44DF
    [W4] = Maxi34SF
     
     
    For w21 = 0 To W
        For z21 = 1 To Maxi21SF
            For w41 = 0 To W - w21
                For z41 = 1 To Maxi41DF
                    For w31 = 0 To W - (w21 + w41)
                        For z31 = 1 To Maxi31SF
                            For w22 = 0 To W - (w21 + w41 + w31)
                                For z22 = 1 To Maxi22SF
                                    For w42 = 0 To W - (w21 + w41 + w31 + w22)
                                        For z42 = 1 To Maxi42DF
                                            For w32 = 0 To W - (w21 + w41 + w31 + w22 + w42)
                                                For z32 = 1 To Maxi32SF
                                                    For w23 = 0 To W - (w21 + w41 + w31 + w22 + w42 + w32)
                                                        For z23 = 1 To Maxi23SF
                                                            For w43 = 0 To W - (w21 + w41 + w31 + w22 + w42 + w32 + w23)
                                                                For z43 = 1 To Maxi43DF
                                                                    For w33 = 0 To W - (w21 + w41 + w31 + w22 + w42 + w32 + w23 + w43)
                                                                        For z33 = 1 To Maxi33SF
                                                                            For w24 = 0 To W - (w21 + w41 + w31 + w22 + w42 + w32 + w23 + w43 + w33)
                                                                                For z24 = 1 To Maxi24SF
                                                                                    For w44 = 0 To W - (w21 + w41 + w31 + w22 + w42 + w32 + w23 + w43 + w33 + w24)
                                                                                        For z44 = 1 To Maxi44DF
                                                                                            For w34 = 0 To W - (w21 + w41 + w31 + w22 + w42 + w32 + w23 + w43 + w33 + w24 + w44)
                                                                                                For z34 = 1 To Maxi34SF
     
     
                                                                                                A = z21 * w21 * 6 + z41 * w41 * 6 + z22 * w22 * 8 + z42 * w42 * 8 + z23 * w23 * 10 + z43 * w43 * 10 + z24 * w24 * 12 + z44 * w44 * 12
     
                                                                                                B = z31 * w31 * 6 + z41 * w41 * 6 + z32 * w32 * 8 + z42 * w42 * 8 + z33 * w33 * 10 + z43 * w43 * 10 + z34 * w34 * 12 + z44 * w44 * 12
     
                                                                                                If (Aa < A And A <= Ab) And (Ba < B And B <= Bb) Then
     
     
                                                                                                N21 = z21 * w21
                                                                                                N41 = z41 * w41
                                                                                                N31 = z31 * w31
                                                                                                N22 = z22 * w22
                                                                                                N42 = z42 * w42
                                                                                                N32 = z32 * w32
                                                                                                N23 = z23 * w23
                                                                                                N43 = z43 * w43
                                                                                                N33 = z33 * w33
                                                                                                N24 = z24 * w24
                                                                                                N44 = z44 * w44
                                                                                                N34 = z34 * w34
     
                                                                                                s21 = N21 * T21
                                                                                                s41 = N41 * T41
                                                                                                s31 = N31 * T31
                                                                                                s22 = N22 * T22
                                                                                                s42 = N42 * T42
                                                                                                s32 = N32 * T32
                                                                                                s23 = N23 * T23
                                                                                                s43 = N43 * T43
                                                                                                s33 = N33 * T33
                                                                                                s24 = N24 * T24
                                                                                                s44 = N44 * T44
                                                                                                s34 = N34 * T34
     
                                                                                                'initialisation des valeurs de X
                                                                                                X21 = 0
                                                                                                X41 = 0
                                                                                                X31 = 0
                                                                                                X22 = 0
                                                                                                X42 = 0
                                                                                                X32 = 0
                                                                                                X23 = 0
                                                                                                X43 = 0
                                                                                                X33 = 0
                                                                                                X24 = 0
                                                                                                X44 = 0
                                                                                                X34 = 0
     
                                                                                                'intialisation des temps restants
                                                                                                TapresT21 = 0
                                                                                                TapresT41 = 0
                                                                                                TapresT31 = 0
                                                                                                TapresT22 = 0
                                                                                                TapresT42 = 0
                                                                                                TapresT32 = 0
                                                                                                TapresT23 = 0
                                                                                                TapresT43 = 0
                                                                                                TapresT33 = 0
                                                                                                TapresT24 = 0
                                                                                                TapresT44 = 0
                                                                                                TapresT34 = 0
     
                                                                                                'a) si N21=N41=N31=0, on va à la ligne suivante
                                                                                                If Not (N21 = 0 And N41 = 0 And N31 = 0) Then
     
     
                                                                                                    'on détermine le nombre de camions qu'il faut pour le simple fret
                                                                                                    'on cherche X21 tq Maxi*(X21-1)<=s21<=Maxi*X21
                                                                                                    If Int(N21 / Maxi21SF) < N21 / Maxi21SF Then X21 = Int(N21 / Maxi21SF) + 1 Else X21 = N21 / Maxi21SF
     
                                                                                                    'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                                                                    MaxiT21 = X21 * maxi
     
                                                                                                    'tps libre du dernier camion de la flotte
                                                                                                    TapresT21 = (MaxiT21 - s21)
     
                                                                                                    'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                                                                    If T21 <= TapresT21 And TapresT21 < T41 Then GoTo suite
     
                                                                                                    'on détermine le nb de camions qu'il faut pour le double fret
                                                                                                    TSFDF21 = Int(TapresT21 / T41) 'nb de tours en DF du dernier camion de SF
     
                                                                                                    'on détermine le nb de camions qu'il faut pour le simple fret
                                                                                                    TSFSF2131 = Int(TapresT21 / T31)
     
     
                                                                                                    If N41 = 0 Then
                                                                                                        X41 = 0
                                                                                                        If Int((N31 - TSFSF2131) / Maxi31SF) < ((N31 - TSFSF2131) / Maxi31SF) Then X31 = Int((N31 - TSFSF2131) / Maxi31SF) + 1 Else X31 = ((N31 - TSFSF2131) / Maxi31SF)
                                                                                                    Else
                                                                                                        If Int((N41 - TSFDF21) / Maxi41DF) < ((N41 - TSFDF21) / Maxi41DF) Then X41 = Int((N41 - TSFDF21) / Maxi41DF) + 1 Else X41 = Int((N41 - TSFDF21) / Maxi41DF)
                                                                                                    End If
     
     
     
                                                                                                    If X31 <> 0 Then TapresT31 = ((X31 * Maxi31SF) - (N31 - TSFSF2131)) * T31 Else TapresT31 = 0
     
                                                                                                    If X41 <> 0 Then TapresT41 = ((X41 * Maxi41DF) - (N41 - TSFDF21)) * T41 Else TapresT41 = 0
     
                                                                                                    'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                                                                    If T41 <= TapresT41 And TapresT41 < T31 Then GoTo suite
     
                                                                                                    'on détermine le nb de camions de DF qui partent en SF r
                                                                                                    TSFDF31 = Int(TapresT41 / T31)
     
                                                                                                    If N31 = 0 Then
                                                                                                        X31 = 0
                                                                                                    Else
                                                                                                        If Int((N31 - TSFDF31) / Maxi31SF) < ((N31 - TSFDF31) / Maxi31SF) Then X31 = ((N31 - TSFDF31) / Maxi31SF) + 1 Else X31 = ((N31 - TSFDF31) / Maxi31SF)
     
                                                                                                    End If
                                                                                                End If
     
                                                                                                If X31 <> 0 Then TapresT31 = ((X31 * Maxi31SF) - (N31 - TSFDF31)) * T31 Else TapresT31 = 0
     
                                                                                                'on regarde si le camion est correctement utilisé
                                                                                                If T31 < TapresT31 Then GoTo suite
     
     
     
                                                                                                'b) si N22=N42=N32=0, on va à la ligne suivante
                                                                                                If Not (N22 = 0 And N42 = 0 And N32 = 0) Then
     
     
                                                                                                    'on détermine le nombre de camions qu'il faut pour le simple fret
                                                                                                    'on cherche X22 tq Maxi*(X22-1)<=s22<=Maxi*X22
                                                                                                    If Int(N22 / Maxi22SF) < N22 / Maxi22SF Then X22 = Int(N22 / Maxi22SF) + 1 Else X22 = N22 / Maxi22SF
     
                                                                                                    'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                                                                    MaxiT22 = X22 * maxi
     
                                                                                                    'tps libre du dernier camion de la flotte
                                                                                                    TapresT22 = (MaxiT22 - s22)
     
                                                                                                    'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                                                                    If T22 <= TapresT22 And TapresT22 < T42 Then GoTo suite
     
                                                                                                    'on détermine le nb de camions qu'il faut pour le double fret
                                                                                                    TSFDF22 = Int(TapresT22 / T42) 'nb de tours en DF du dernier camion de SF
     
                                                                                                    'on détermine le nb de camions qu'il faut pour le simple fret
                                                                                                    TSFSF2232 = Int(TapresT22 / T32)
     
     
                                                                                                    If N42 = 0 Then
                                                                                                        X42 = 0
                                                                                                        If Int((N32 - TSFSF2232) / Maxi32SF) < ((N32 - TSFSF2232) / Maxi32SF) Then X32 = Int((N32 - TSFSF2232) / Maxi32SF) + 1 Else X32 = ((N32 - TSFSF2232) / Maxi32SF)
                                                                                                    Else
                                                                                                        If Int((N42 - TSFDF22) / Maxi42DF) < ((N42 - TSFDF22) / Maxi42DF) Then X42 = Int((N42 - TSFDF22) / Maxi42DF) + 1 Else X42 = Int((N42 - TSFDF22) / Maxi42DF)
                                                                                                    End If
     
     
     
                                                                                                    If X32 <> 0 Then TapresT32 = ((X32 * Maxi32SF) - (N32 - TSFSF2232)) * T32 Else TapresT32 = 0
     
                                                                                                    If X42 <> 0 Then TapresT42 = ((X42 * Maxi42DF) - (N42 - TSFDF22)) * T42 Else TapresT42 = 0
     
                                                                                                    'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                                                                    If T42 <= TapresT42 And TapresT42 < T32 Then GoTo suite
     
                                                                                                    'on détermine le nb de camions de DF qui partent en SF r
                                                                                                    TSFDF32 = Int(TapresT42 / T32)
     
                                                                                                    If N32 = 0 Then
                                                                                                        X32 = 0
                                                                                                    Else
                                                                                                        If Int((N32 - TSFDF32) / Maxi32SF) < ((N32 - TSFDF32) / Maxi32SF) Then X32 = ((N32 - TSFDF32) / Maxi32SF) + 1 Else X32 = ((N32 - TSFDF32) / Maxi32SF)
     
                                                                                                    End If
                                                                                                End If
     
                                                                                                If X32 <> 0 Then TapresT32 = ((X32 * Maxi32SF) - (N32 - TSFDF32)) * T32 Else TapresT32 = 0
     
                                                                                                'on regarde si le camion est correctement utilisé
                                                                                                If T32 < TapresT32 Then GoTo suite
     
     
     
                                                                                                'c) si N23=N43=N33=0, on va à la ligne suivante
                                                                                                If Not (N23 = 0 And N43 = 0 And N33 = 0) Then
     
     
                                                                                                    'on détermine le nombre de camions qu'il faut pour le simple fret
                                                                                                    'on cherche X23 tq Maxi*(X23-1)<=s23<=Maxi*X23
                                                                                                    If Int(N23 / Maxi23SF) < N23 / Maxi23SF Then X23 = Int(N23 / Maxi23SF) + 1 Else X23 = N23 / Maxi23SF
     
                                                                                                    'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                                                                    MaxiT23 = X23 * maxi
     
                                                                                                    'tps libre du dernier camion de la flotte
                                                                                                    TapresT23 = (MaxiT23 - s23)
     
                                                                                                    'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                                                                    If T23 <= TapresT23 And TapresT23 < T43 Then GoTo suite
     
                                                                                                    'on détermine le nb de camions qu'il faut pour le double fret
                                                                                                    TSFDF23 = Int(TapresT23 / T43) 'nb de tours en DF du dernier camion de SF
     
                                                                                                    'on détermine le nb de camions qu'il faut pour le simple fret
                                                                                                    TSFSF2333 = Int(TapresT23 / T33)
     
     
                                                                                                    If N43 = 0 Then
                                                                                                        X43 = 0
                                                                                                        If Int((N33 - TSFSF2333) / Maxi33SF) < ((N33 - TSFSF2333) / Maxi33SF) Then X33 = Int((N33 - TSFSF2333) / Maxi33SF) + 1 Else X33 = ((N33 - TSFSF2333) / Maxi33SF)
                                                                                                    Else
                                                                                                        If Int((N43 - TSFDF23) / Maxi43DF) < ((N43 - TSFDF23) / Maxi43DF) Then X43 = Int((N43 - TSFDF23) / Maxi43DF) + 1 Else X43 = Int((N43 - TSFDF23) / Maxi43DF)
                                                                                                    End If
     
     
     
                                                                                                    If X33 <> 0 Then TapresT33 = ((X33 * Maxi33SF) - (N33 - TSFSF2333)) * T33 Else TapresT33 = 0
     
                                                                                                    If X43 <> 0 Then TapresT43 = ((X43 * Maxi43DF) - (N43 - TSFDF23)) * T43 Else TapresT43 = 0
     
                                                                                                    'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                                                                    If T43 <= TapresT43 And TapresT43 < T33 Then GoTo suite
     
                                                                                                    'on détermine le nb de camions de DF qui partent en SF r
                                                                                                    TSFDF33 = Int(TapresT43 / T33)
     
                                                                                                    If N33 = 0 Then
                                                                                                        X33 = 0
                                                                                                    Else
                                                                                                        If Int((N33 - TSFDF33) / Maxi33SF) < ((N33 - TSFDF33) / Maxi33SF) Then X33 = ((N33 - TSFDF33) / Maxi33SF) + 1 Else X33 = ((N33 - TSFDF33) / Maxi33SF)
     
                                                                                                    End If
                                                                                                End If
     
                                                                                                If X33 <> 0 Then TapresT33 = ((X33 * Maxi33SF) - (N33 - TSFDF33)) * T33 Else TapresT33 = 0
     
                                                                                                'on regarde si le camion est correctement utilisé
                                                                                                If T33 < TapresT33 Then GoTo suite
     
     
     
                                                                                                'd) si N24=N44=N34=0, on va à la ligne suivante
                                                                                                If Not (N24 = 0 And N44 = 0 And N34 = 0) Then
     
     
                                                                                                    'on détermine le nombre de camions qu'il faut pour le simple fret
                                                                                                    'on cherche X24 tq Maxi*(X24-1)<=s24<=Maxi*X24
                                                                                                    If Int(N24 / Maxi24SF) < N24 / Maxi24SF Then X24 = Int(N24 / Maxi24SF) + 1 Else X24 = N24 / Maxi24SF
     
                                                                                                    'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                                                                    MaxiT24 = X24 * maxi
     
                                                                                                    'tps libre du dernier camion de la flotte
                                                                                                    TapresT24 = (MaxiT24 - s24)
     
                                                                                                    'On regarde si le camion ne va pas etre sous utilisé On passe au cas suivant
                                                                                                    If T24 <= TapresT24 And TapresT24 < T44 Then GoTo suite
     
                                                                                                    'on détermine le nb de camions qu'il faut pour le double fret
                                                                                                    TSFDF24 = Int(TapresT24 / T44) 'nb de tours en DF du dernier camion de SF
     
                                                                                                    'on détermine le nb de camions qu'il faut pour le simple fret
                                                                                                    TSFSF2434 = Int(TapresT24 / T34)
     
     
                                                                                                    If N44 = 0 Then
                                                                                                        X44 = 0
                                                                                                        If Int((N34 - TSFSF2434) / Maxi34SF) < ((N34 - TSFSF2434) / Maxi34SF) Then X34 = Int((N34 - TSFSF2434) / Maxi34SF) + 1 Else X34 = ((N34 - TSFSF2434) / Maxi34SF)
                                                                                                    Else
                                                                                                        If Int((N44 - TSFDF24) / Maxi44DF) < ((N44 - TSFDF24) / Maxi44DF) Then X44 = Int((N44 - TSFDF24) / Maxi44DF) + 1 Else X44 = Int((N44 - TSFDF24) / Maxi44DF)
                                                                                                    End If
     
     
     
                                                                                                    If X34 <> 0 Then TapresT34 = ((X34 * Maxi34SF) - (N34 - TSFSF2434)) * T34 Else TapresT34 = 0
     
                                                                                                    If X44 <> 0 Then TapresT44 = ((X44 * Maxi44DF) - (N44 - TSFDF24)) * T44 Else TapresT44 = 0
     
                                                                                                    'On regarde si le camion ne va pas etre sous utiliséOn passe au cas suivant
                                                                                                    If T44 <= TapresT44 And TapresT44 < T34 Then GoTo suite
     
                                                                                                    'on détermine le nb de camions de DF qui partent en SF r
                                                                                                    TSFDF34 = Int(TapresT44 / T34)
     
                                                                                                    If N34 = 0 Then
                                                                                                        X34 = 0
                                                                                                    Else
                                                                                                        If Int((N34 - TSFDF34) / Maxi34SF) < ((N34 - TSFDF34) / Maxi34SF) Then X34 = ((N34 - TSFDF34) / Maxi34SF) + 1 Else X34 = ((N34 - TSFDF34) / Maxi34SF)
     
                                                                                                    End If
                                                                                                End If
     
                                                                                                If X34 <> 0 Then TapresT34 = ((X34 * Maxi34SF) - (N34 - TSFDF34)) * T34 Else TapresT34 = 0
     
                                                                                                'on regarde si le camion est correctement utilisé
                                                                                                If T34 < TapresT34 Then GoTo suite
     
     
     
                                                                                                'on vérifie que cette solution n'est pas déjà présente
                                                                                                Xtot1 = X21 + X41 + X31
                                                                                                Xtot2 = X22 + X42 + X32
                                                                                                Xtot3 = X23 + X43 + X33
                                                                                                Xtot4 = X24 + X44 + X34
     
                                                                                                'on regroupe ttes les infos qui caractérisent la ligne, les N, A, B, Xtot2, Xtot2, Xtot3, Xtot4
                                                                                                StrAntiDoublon = CStr(N21) & "-" & CStr(N41) & "-" & CStr(N31) & "-" & CStr(N22) & "-" & CStr(N42) & "-" & CStr(N32) & "-" & CStr(N23) & "-" & CStr(N43) & "-" & CStr(N33) & "-" & CStr(N24) & "-" & CStr(N44) & "-" & CStr(N34) & "-" & CStr(A) & "-" & CStr(B) & "-" & CStr(Xtot1) & "-" & CStr(Xtot2) & "-" & CStr(Xtot2) & "-" & CStr(Xtot3) & "-" & CStr(Xtot4)
     
                                                                                                'on regarde si ces infos existent déja
                                                                                                If DicoAntiDoublon.exists(StrAntiDoublon) Then GoTo suite
     
                                                                                                'on les rajoute puisqu'elles ne figurent pas
                                                                                                DicoAntiDoublon.Add StrAntiDoublon, 0
     
     
     
     
                                                                                                'Si le code arrive ici c'est que notre flotte est bien occupé, donc on note les résultats dans le tableau
     
                                                                                                Cells(Ligne, "A").Value = z21 * w21
                                                                                                Cells(Ligne, "B").Value = z41 * w41
                                                                                                Cells(Ligne, "C").Value = z31 * w31
                                                                                                Cells(Ligne, "D").Value = z22 * w22
                                                                                                Cells(Ligne, "E").Value = z42 * w42
                                                                                                Cells(Ligne, "F").Value = z32 * w32
                                                                                                Cells(Ligne, "G").Value = z23 * w23
                                                                                                Cells(Ligne, "H").Value = z43 * w43
                                                                                                Cells(Ligne, "I").Value = z33 * w33
                                                                                                Cells(Ligne, "J").Value = z24 * w24
                                                                                                Cells(Ligne, "K").Value = z44 * w44
                                                                                                Cells(Ligne, "L").Value = z34 * w34
                                                                                                Cells(Ligne, "M").Value = A
                                                                                                Cells(Ligne, "N").Value = B
     
                                                                                                Cells(Ligne, "P") = N21 * T21
                                                                                                Cells(Ligne, "Q") = N41 * T41
                                                                                                Cells(Ligne, "R") = N31 * T31
                                                                                                Cells(Ligne, "AA") = N22 * T22
                                                                                                Cells(Ligne, "AB") = N42 * T42
                                                                                                Cells(Ligne, "AC") = N32 * T32
                                                                                                Cells(Ligne, "AL") = N23 * T23
                                                                                                Cells(Ligne, "AM") = N43 * T43
                                                                                                Cells(Ligne, "AN") = N33 * T33
                                                                                                Cells(Ligne, "AW") = N24 * T24
                                                                                                Cells(Ligne, "AX") = N44 * T44
                                                                                                Cells(Ligne, "AY") = N34 * T34
     
     
     
                                                                                                'Xtot1 = X21 + X41 + X31
                                                                                                Cells(Ligne, "S") = X21
                                                                                                Cells(Ligne, "T") = TapresT21
                                                                                                Cells(Ligne, "U") = X41
                                                                                                Cells(Ligne, "V") = TapresT41
                                                                                                Cells(Ligne, "W") = X31
                                                                                                Cells(Ligne, "X") = TapresT31
                                                                                                Cells(Ligne, "Y") = Xtot1
     
                                                                                                'Xtot2 = X22 + X42 + X32
                                                                                                Cells(Ligne, "AD") = X22
                                                                                                Cells(Ligne, "AE") = TapresT22
                                                                                                Cells(Ligne, "AF") = X42
                                                                                                Cells(Ligne, "AG") = TapresT42
                                                                                                Cells(Ligne, "AH") = X32
                                                                                                Cells(Ligne, "AI") = TapresT32
                                                                                                Cells(Ligne, "AJ") = Xtot2
     
     
                                                                                                'Xtot3 = X23 + X43 + X33
                                                                                                Cells(Ligne, "AO") = X23
                                                                                                Cells(Ligne, "AP") = TapresT23
                                                                                                Cells(Ligne, "AQ") = X43
                                                                                                Cells(Ligne, "AR") = TapresT43
                                                                                                Cells(Ligne, "AS") = X33
                                                                                                Cells(Ligne, "AT") = TapresT33
                                                                                                Cells(Ligne, "AU") = Xtot3
     
                                                                                                'Xtot4 = X24 + X44 + X34
                                                                                                Cells(Ligne, "AZ") = X24
                                                                                                Cells(Ligne, "BA") = TapresT24
                                                                                                Cells(Ligne, "BB") = X44
                                                                                                Cells(Ligne, "BC") = TapresT44
                                                                                                Cells(Ligne, "BD") = X34
                                                                                                Cells(Ligne, "BE") = TapresT34
                                                                                                Cells(Ligne, "BF") = Xtot4
     
                                                                                                Cells(Ligne, "BH") = (X21 + X41 + X31) * 420 + (X22 + X42 + X32) * 480 + (X23 + X43 + X33) * 550 + (X24 + X44 + X34) * 600
     
                                                                                                Ligne = Ligne + 1
     
                                                                                             End If
    suite:
                                                                                             Next
                                                                                        Next
                                                                                    Next
                                                                                Next
                                                                            Next
                                                                        Next
                                                                    Next
                                                                Next
     
     
     
     
                                                                Next
                                                            Next
                                                        Next
                                                    Next
                                                Next
                                            Next
                                        Next
                                    Next
     
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
    Next
     
    DicoAntiDoublon.RemoveAll
    Set DicoAntiDoublon = Nothing
    Application.ScreenUpdating = True
     
     
    End Sub
    et voici ma trame: http://cjoint.com/?etrleMkxxd

  11. #51
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    2) je suis restée avec mes deux types de camions mais j'ai à 1 déblais et 2 remblais.

    Voici la macro:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    Option Explicit 'indique les variables non déclarées
     
    Sub combinaison()
     
    Dim N22D1 As Integer, N42D1 As Integer, N23D1 As Integer, N43D1 As Integer, N32R1 As Integer, N33R1 As Integer, N32R2 As Integer, N33R2 As Integer, N421R1 As Integer, N422R2 As Integer, N431R1 As Integer, N432R2 As Integer, z22D1 As Integer, z42D1 As Integer, z23D1 As Integer, z43D1 As Integer, z32R1 As Integer, z33R1 As Integer, z32R2 As Integer, z33R2 As Integer, z421R1 As Integer, z422R2 As Integer, z431R1 As Integer, z432R2 As Integer, w22D1 As Integer, w42D1 As Integer, w23D1 As Integer, w43D1 As Integer, w32R1 As Integer, w33R1 As Integer, w32R2 As Integer, w33R2 As Integer, w421R1 As Integer, w422R2 As Integer, w431R1 As Integer, w432R2 As Integer, W As Integer, A As Integer, Aa As Integer, Ab As Integer, B As Integer, Ba As Integer, Bb As Integer
    Dim T22D1 As Single, s22D1 As Single, T32R1 As Single, s32R1 As Single, T32R2 As Single, s32R2 As Single, T42D1R1 As Single, s421R1 As Single, T42D1R2 As Single, s422R2 As Single, T23D1 As Single, s23D1 As Single, T33R1 As Single, s33R1 As Single, T33R2 As Single, s33R2 As Single, T43D1R1 As Single, s431R1 As Single, T43D1R2 As Single, s432R2 As Single
    Dim X22D1 As Integer, X42D1 As Integer, X32R1 As Integer, X32R2 As Integer, X421R1 As Integer, X422R2 As Integer, X23D1 As Integer, X43D1 As Integer, X33R1 As Integer, X33R2 As Integer, X431R1 As Integer, X432R2 As Integer, Xtot2 As Integer, Xtot3 As Integer
    Dim maxi As Integer, Maxi22D1SF As Integer, Maxi32R1SF As Integer, Maxi32R2SF As Integer, Maxi421DF As Integer, Maxi422DF As Integer, Maxi23D1SF As Integer, Maxi33R1SF As Integer, Maxi33R2SF As Integer, Maxi431DF As Integer, Maxi432DF As Integer, MaxiT421DF As Single, MaxiT431DF As Single, TapresT22D1 As Single, TapresT32R1 As Single, TapresT32R2 As Single, TapresT421R1 As Single, TapresT422R2 As Single, TapresT23D1 As Single, TapresT33R1 As Single, TapresT33R2 As Single, TapresT431R1 As Single, TapresT432R2 As Single, TDFDF2R1R2 As Integer, TDFSF2R1R1 As Integer, TDFSF2R1R2 As Integer, TDFSF2R1D1 As Integer, TDFDF2R2R2 As Integer, TDFSF2R2R1 As Integer, TDFSF2R2D1 As Integer, TSFSF2D1R2 As Integer, TSFSF2D1R1, TSFSF2R1R2 As Integer, TDFDF3R1R2 As Integer, TDFSF3R1R1 As Integer, TDFSF3R1R2 As Integer, TDFSF3R1D1 As Integer, TDFDF3R2R2 As Integer, TDFSF3R2R1 As Integer, TDFSF3R2D1 As Integer, TSFSF3D1R2 As Integer, TSFSF3D1R1, TSFSF3R1R2 As Integer
    Dim Ligne As Long, PT As Integer
    Dim a22D1 As Integer, a42D1 As Integer, a23D1 As Integer, a43D1 As Integer, a32R1 As Integer, a32R2 As Integer, a421R1 As Integer, a422R2 As Integer, a33R1 As Integer, a33R2 As Integer, a431R1 As Integer, a432R2 As Integer
    Dim DicoAntiDoublon As New dictionary, StrAntiDoublon As String
     
    'On stop le refraichissement pour eviter le scintillement et gagner en vitesse
    Application.ScreenUpdating = False
     
    [A7.BA65536].ClearContents
    [M2].ClearContents
    [O2].ClearContents
    [Q2].ClearContents
    [S2].ClearContents
    [U2].ClearContents
    [M4].ClearContents
    [O4].ClearContents
    [Q4].ClearContents
    [S4].ClearContents
    [U4].ClearContents
     
     
    W = [A3] 'nb max camion/jour
    Ab = [C3] 'rdt/jour en déblais
    Aa = [C1] 'rdt limite/jour en déblais
    Bb = [E3] 'rdt/jour en remblais
    Ba = [E1] 'rdt limite/jour en remblais
    T22D1 = [G1]
    T42D1R1 = [G3]
    T32R1 = [G5]
    T42D1R2 = [G7]
    T32R2 = [G9]
    T23D1 = [I1]
    T43D1R1 = [I3]
    T33R1 = [I5]
    T43D1R2 = [I7]
    T33R2 = [I9]
    maxi = [A5] 'nb heures travaillées max
    Ligne = 11
     
    Maxi22D1SF = Int(maxi / T22D1) 'nb maxi de tours/camions/jour en SF(8m3) en D1
    Maxi32R1SF = Int(maxi / T32R1) 'nb maxi de tours/camions/jour en SF(8m3) en R1
    Maxi32R2SF = Int(maxi / T32R2) 'nb maxi de tours/camions/jour en SF(8m3) en R2
    Maxi421DF = Int(maxi / T42D1R1) 'nb maxi de tours/camions/jour en DF(8m3) D1/R1
    Maxi422DF = Int(maxi / T42D1R2) 'nb maxi de tours/camion/jour en DF(8m3) DI/R2
    'Maxi42DF = Maxi421DF + Maxi422DF 'pb car sur une journée boucle for?
     
    Maxi23D1SF = Int(maxi / T23D1) 'nb maxi de tours/camions/jour en SF(10m3) en D1
    Maxi33R1SF = Int(maxi / T33R1) 'nb maxi de tours/camions/jour en SF(10m3) en R1
    Maxi33R2SF = Int(maxi / T33R2) 'nb maxi de tours/camions/jour en SF(10m3) en R2
    Maxi431DF = Int(maxi / T43D1R1) 'nb maxi de tours/camions/jour en DF(10m3) D1/R1
    Maxi432DF = Int(maxi / T43D1R2) 'nb maxi de tours/camion/jour en DF(10m3) DI/R2
    'Maxi43DF = Maxi431DF + Maxi432DF 'pb car sur une journée
     
     
     
    'Il vaut mieux mettre ca ici plutot que de le repeter a chaque boucle
    [M2] = Maxi22D1SF
    [O2] = Maxi32R1SF
    [Q2] = Maxi32R2SF
    [S2] = Maxi421DF
    [U2] = Maxi422DF
    [M4] = Maxi23D1SF
    [O4] = Maxi33R1SF
    [Q4] = Maxi33R2SF
    [S4] = Maxi431DF
    [U4] = Maxi432DF
     
     
    For w22D1 = 0 To W
        For z22D1 = 1 To Maxi22D1SF
            For w32R1 = 0 To W - w22D1
                For z32R1 = 1 To Maxi32R1SF
                    For w32R2 = 0 To W - (w22D1 + w32R1)
                        For z32R2 = 1 To Maxi32R2SF
                            For w421R1 = 0 To W - (w22D1 + w32R1 + w32R2)
                                For z421R1 = 1 To Maxi421DF
                                    For w422R2 = 0 To W - (w22D1 + w32R1 + w32R2 + w421R1)
                                        For z422R2 = 1 To Maxi422DF
                                            For w23D1 = 0 To W - (w22D1 + w32R1 + w32R2 + w421R1 + w422R2)
                                                For z23D1 = 1 To Maxi23D1SF
                                                    For w33R1 = 0 To W - (w22D1 + w32R1 + w32R2 + w421R1 + w422R2 + w23D1)
                                                        For z33R1 = 1 To Maxi33R1SF
                                                            For w33R2 = 0 To W - (w22D1 + w32R1 + w32R2 + w421R1 + w422R2 + w23D1 + w33R1)
                                                                For z33R2 = 1 To Maxi33R2SF
                                                                    For w431R1 = 1 To W - (w22D1 + w32R1 + w32R2 + w421R1 + w422R2 + w23D1 + w33R1 + w33R2)
                                                                        For z431R1 = 1 To Maxi431DF
                                                                            For w432R2 = 0 To W - (w22D1 + w32R1 + w32R2 + w421R1 + w422R2 + w23D1 + w33R1 + w33R2 + w431R1)
                                                                                For z432R2 = 1 To Maxi432DF
     
     
     
                                                                                A = z22D1 * w22D1 * 8 + (z421R1 * w421R1 + z422R2 * w422R2) * 8 + z23D1 * w23D1 * 10 + (z431R1 * w431R1 + z432R2 * w432R2) * 10
                                                                                B = z32R1 * w32R1 * 8 + z32R2 * w32R2 * 8 + (z421R1 * w421R1 + z422R2 * w422R2) * 8 + z33R1 * w33R1 * 10 + z33R2 * w33R2 * 10 + (z431R1 * w431R1 + z432R2 * w432R2) * 10
     
                                                                                If (Aa < A And A <= Ab) And (Ba < B And B <= Bb) Then
                                                                                    If ((z421R1 * T42D1R1 + z422R2 * T42D1R2) <= maxi) And ((z431R1 * T43D1R1 + z432R2 * T43D1R2) <= maxi) Then
     
     
                                                                                    'z421R1 * T42D1R1 + z422R2 * T42D1R2 <=Maxi
                                                                                    'z431R1 * T43D1R1 + z432R2 * T43D1R2 <=Maxi
     
                                                                                    N22D1 = z22D1 * w22D1
                                                                                    N421R1 = z421R1 * w421R1
                                                                                    N422R2 = z422R2 * w422R2
                                                                                    N32R1 = z32R1 * w32R1
                                                                                    N32R2 = z32R2 * w32R2
                                                                                    N42D1 = N421R1 + N422R2
     
                                                                                    N23D1 = z23D1 * w23D1
                                                                                    N431R1 = z431R1 * w431R1
                                                                                    N432R2 = z432R2 * w432R2
                                                                                    N33R1 = z33R1 * w33R1
                                                                                    N33R2 = z33R2 * w33R2
                                                                                    N43D1 = N431R1 + N432R2
     
     
     
                                                                                    s22D1 = N22D1 * T22D1
                                                                                    s421R1 = N421R1 * T42D1R1
                                                                                    s422R2 = N422R2 * T42D1R2
                                                                                    s32R1 = N32R1 * T32R1
                                                                                    s32R2 = N32R2 * T32R2
     
                                                                                    s23D1 = N23D1 * T23D1
                                                                                    s431R1 = N431R1 * T43D1R1
                                                                                    s432R2 = N432R2 * T43D1R2
                                                                                    s33R1 = N33R1 * T33R1
                                                                                    s33R2 = N33R2 * T33R2
     
                                                                                    'initialisation des valeurs de X
                                                                                    X22D1 = 0
                                                                                    X42D1 = 0
                                                                                    X421R1 = 0
                                                                                    X422R2 = 0
                                                                                    X32R1 = 0
                                                                                    X32R2 = 0
                                                                                    X23D1 = 0
                                                                                    X43D1 = 0
                                                                                    X431R1 = 0
                                                                                    X432R2 = 0
                                                                                    X33R1 = 0
                                                                                    X33R2 = 0
     
                                                                                    'initialisation des temps restants
                                                                                    TapresT22D1 = 0
                                                                                    TapresT421R1 = 0
                                                                                    TapresT422R2 = 0
                                                                                    TapresT32R1 = 0
                                                                                    TapresT32R2 = 0
                                                                                    TapresT23D1 = 0
                                                                                    TapresT431R1 = 0
                                                                                    TapresT432R2 = 0
                                                                                    TapresT33R1 = 0
                                                                                    TapresT33R2 = 0
     
     
     
                                                                                    'a) si N22D1=N421R1=N422R2=N32R1=N32R2=0, on va à la ligne suivante
                                                                                    If Not (N22D1 = 0 And N421R1 = 0 And N422R2 = 0 And N32R1 = 0 And N32R2 = 0) Then
     
     
                                                                                        'on détermine le nombre de camions qu'il faut pour le double fret D1/R1
                                                                                        'on cherche X421R1 tq Maxi*(X421R1-1)<=s421R1<=Maxi*X421R1
                                                                                        If Int(N421R1 / Maxi421DF) < N421R1 / Maxi421DF Then X421R1 = Int(N421R1 / Maxi421DF) + 1 Else X421R1 = N421R1 / Maxi421DF
     
                                                                                        'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                                                        MaxiT421DF = X421R1 * maxi
     
                                                                                        'tps libre du dernier camion de la flotte
                                                                                        TapresT421R1 = (MaxiT421DF - s421R1)
     
                                                                                        'On regarde si le camion ne va pas etre sous utilisé sinon on passe au cas suivant
                                                                                        If T42D1R1 <= TapresT421R1 And TapresT421R1 < T42D1R2 Then GoTo suite
     
                                                                                        'on détermine le nb de camions qu'il faut pour le double fret avec le R2
                                                                                        TDFDF2R1R2 = Int(TapresT421R1 / T42D1R2) 'nb de tours en DF r2 du dernier camion de DF r1
     
                                                                                        'on détermine le nb de camions qu'il faut pour le simple fret déblais
                                                                                        TDFSF2R1D1 = Int(TapresT421R1 / T22D1) 'nb de tours en SF d du dernier camion en DF r1
     
                                                                                        'on détermine le nb de camions qu'il faut pour le simple fret R1
                                                                                        TDFSF2R1R1 = Int(TapresT421R1 / T32R1) 'nb de tours en SF R1 du dernier camion en DF r1
     
                                                                                        'on détermine le nb de camions qu'il faut pour le simple fret R2
                                                                                        TDFSF2R1R2 = Int(TapresT421R1 / T32R2) 'nb de tours en SF R2 du dernier camion en DF r1
     
     
                                                                                        If N422R2 = 0 Then
                                                                                            X422R2 = 0
                                                                                            If N22D1 = 0 Then
                                                                                                X22D1 = 0
                                                                                                If N32R1 = 0 Then
                                                                                                    X32R1 = 0
                                                                                                    If Int((N32R2 - TDFSF2R1R2) / Maxi32R2SF) < ((N32R2 - TDFSF2R1R2) / Maxi32R2SF) Then X32R2 = Int((N32R2 - TDFSF2R1R2) / Maxi32R2SF) + 1 Else X32R2 = Int((N32R2 - TDFSF2R1R2) / Maxi32R2SF)
                                                                                                Else
                                                                                                    If Int((N32R1 - TDFSF2R1R1) / Maxi32R1SF) < ((N32R1 - TDFSF2R1R1) / Maxi32R1SF) Then X32R1 = Int((N32R1 - TDFSF2R1R1) / Maxi32R1SF) + 1 Else X32R1 = Int((N32R1 - TDFSF2R1R1) / Maxi32R1SF)
                                                                                            Else
                                                                                                If Int((N22D1 - TDFSF2R1D1) / Maxi22D1SF) < ((N22D1 - TDFSF2R1D1) / Maxi22D1SF) Then X22D1 = Int((N22D1 - TDFSF2R1D1) / Maxi22D1SF) + 1 Else X22D1 = Int((N22D1 - TDFSF2R1D1) / Maxi22D1SF)
                                                                                        Else
                                                                                            If Int((N422R2 - TDFDF2R1R2) / Maxi422) < ((N422R2 - TDFDF2R1R2) / Maxi422) Then X422R2 = Int((N422R2 - TDFDF2R1R2) / Maxi422) + 1 Else X422R2 = Int((N422R2 - TDFDF2R1R2) / Maxi422)
                                                                                        End If
     
                                                                                        If X32R2 <> 0 Then TapresT32R2 = ((X32R2 * Maxi32R2SF) - (N32R2 - TDFSF2R1R2)) * T32R2 Else TapresT32R2 = 0
     
                                                                                        If X32R1 <> 0 Then TapresT32R1 = ((X32R1 * Maxi32R1SF) - (N32R1 - TDFSF2R1R1)) * T32R1 Else TapresT32R1 = 0
     
                                                                                        If X22D1 <> 0 Then TapresT22D1 = ((X22D1 * Maxi22D1SF) - (N22D1 - TDFSF2R1D1)) * T22D1 Else TapresT22D1 = 0
     
                                                                                        If X422R2 <> 0 Then TapresT422R2 = ((X422R2 * Maxi422) - (N422R2 - TDFDF2R1R2)) * T42D1R2 Else TapresT422R2 = 0
     
                                                                                        If T42D1R2 <= TapresT422R2 And TapresT422R2 < T22D1 Then GoTo suite
     
     
                                                                                        TDFDF2R2R2 = Int(TapresT422R2 / T32R2)
                                                                                        TDFSF2R2R1 = Int(TapresT422R2 / T32R1)
                                                                                        TDFSF2R2D1 = Int(TapresT422R2 / T22D1)
     
     
                                                                                        If N22D1 = 0 Then
                                                                                            X22D1 = 0
                                                                                            If N32R1 = 0 Then
                                                                                                X32R1 = 0
                                                                                                If Int((N32R2 - TDFSF2R2R2) / Maxi32R2SF) < ((N32R2 - TDFSF2R2R2) / Maxi32R2SF) Then X32R2 = Int((N32R2 - TDFSF2R2R2) / Maxi32R2SF) + 1 Else X32R2 = Int((N32R2 - TDFSF2R2R2) / Maxi32R2SF)
                                                                                            Else
                                                                                                If Int((N32R1 - TDFSF2R2R1) / Maxi32R1SF) < ((N32R1 - TDFSF2R2R1) / Maxi32R1SF) Then X32R1 = Int((N32R1 - TDFSF2R2R1) / Maxi32R1SF) + 1 Else X32R1 = Int((N32R1 - TDFSF2R2R1) / Maxi32R1SF)
                                                                                        Else
                                                                                            If Int((N22D1 - TDFSF2R2D1) / Maxi22D1SF) < ((N22D1 - TDFSF2R2D1) / Maxi22D1SF) Then X22D1 = Int((N22D1 - TDFSF2R2D1) / Maxi22D1SF) + 1 Else X22D1 = Int((N22D1 - TDFSF2R2D1) / Maxi22D1SF)
                                                                                        End If
     
     
                                                                                        If X32R2 <> 0 Then TapresT32R2 = ((X32R2 * Maxi32R2SF) - (N32R2 - TDFSF2R2R2)) * T32R2 Else TapresT32R2 = 0
                                                                                        If X32R1 <> 0 Then TapresT32R1 = ((X32R1 * Maxi32R1SF) - (N32R1 - TDFSF2R2R1)) * T32R1 Else TapresT32R1 = 0
                                                                                        If X22D1 <> 0 Then TapresT22D1 = ((X22D1 * Maxi22D1SF) - (N22D1 - TDFSF2R2D1)) * T22D1 Else TapresT22D1 = 0
     
     
                                                                                        TSFSF2D1R2 = Int(TapresT22D1 / T32R2)
                                                                                        TSFSF2D1R1 = Int(TapresT22D1 / T32R1)
     
                                                                                        If T22D1 <= TapresT22D1 And TapresT22D1 < T32R1 Then GoTo suite
     
                                                                                        If N32R1 = 0 Then
                                                                                            X32R1 = 0
                                                                                            If Int((N32R2 - TSFSF2D1R2) / Maxi32R2SF) < ((N32R2 - TSFSF2D1R2) / Maxi32R2SF) Then X32R2 = Int((N32R2 - TSFSF2D1R2) / Maxi32R2SF) + 1 Else X32R2 = Int((N32R2 - TSFSF2D1R2) / Maxi32R2SF)
                                                                                        Else
                                                                                            If Int((N32R1 - TSFSF2D1R1) / Maxi32R1SF) < ((N32R1 - TSFSF2D1R1) / Maxi32R1SF) Then X32R1 = Int((N32R1 - TSFSF2D1R1) / Maxi32R1SF) + 1 Else X32R1 = Int((N32R1 - TSFSF2D1R1) / Maxi32R1SF)
                                                                                        End If
     
                                                                                        If X32R2 <> 0 Then TapresT32R2 = ((X32R2 * Maxi32R2SF) - (N32R2 - TSFSF2D1R2)) * T32R2 Else TapresT32R2 = 0
     
                                                                                        If X32R1 <> 0 Then TapresT32R1 = ((N32R1 * Maxi32R1SF) - (N32R1 - TSFSF2D1R1)) * T32R1 Else TapresT32R1 = 0
     
     
                                                                                        If T32R1 <= TapresT32R1 And TapresT32R1 < T32R2 Then GoTo suite
     
     
                                                                                        TSFSF2R1R2 = Int(TapresT32R1 / T32R2)
     
                                                                                        If N32R2 = 0 Then
                                                                                            X32R2 = 0
                                                                                        Else
                                                                                            If Int((N32R2 - TSFSF2R1R2) / Maxi32R2SF) < ((N32R2 - TSFSF2R1R2) / Maxi32R2) Then X32R2 = Int((N32R2 - TSFSF2R1R2) / Maxi32R2) + 1 Else X32R2 = Int((N32R2 - TSFSF2R1R2) / Maxi32R2)
                                                                                        End If
                                                                                    End If
     
                                                                                    If X32R2 <> 0 Then TapresT32R2 = ((X32R2 * Maxi32R2SF) - (N32R2 - TSFSF2R1R2)) * T32R2 Else TapresT32R2 = 0
     
                                                                                    If T32R2 <= TapresT32R2 Then GoTo suite
     
     
                                                                                    'b) si N23D1=N431R1=N432R2=N33R1=N33R2=0, on va à la ligne suivante
                                                                                    If Not (N23D1 = 0 And N431R1 = 0 And N432R2 = 0 And N33R1 = 0 And N33R2 = 0) Then
     
     
                                                                                        'on détermine le nombre de camions qu'il faut pour le double fret D1/R1
                                                                                        'on cherche X431R1 tq Maxi*(X431R1-1)<=s431R1<=Maxi*X431R1
                                                                                        If Int(N431R1 / Maxi431DF) < N431R1 / Maxi431DF Then X431R1 = Int(N431R1 / Maxi431DF) + 1 Else X431R1 = N431R1 / Maxi431DF
     
                                                                                        'on cherche le tps maxi en fonction du nb de trajets max que peuvent réaliser les camions
                                                                                        MaxiT431DF = X431R1 * maxi
     
                                                                                        'tps libre du dernier camion de la flotte
                                                                                        TapresT431R1 = (MaxiT431DF - s431R1)
     
                                                                                        'On regarde si le camion ne va pas etre sous utilisé sinon on passe au cas suivant
                                                                                        If T43D1R1 <= TapresT431R1 And TapresT431R1 < T43D1R2 Then GoTo suite
     
                                                                                        'on détermine le nb de camions qu'il faut pour le double fret avec le R2
                                                                                        TDFDF3R1R2 = Int(TapresT431R1 / T43D1R2) 'nb de tours en DF r2 du dernier camion de DF r1
     
                                                                                        'on détermine le nb de camions qu'il faut pour le simple fret déblais
                                                                                        TDFSF3R1D1 = Int(TapresT431R1 / T23D1) 'nb de tours en SF d du dernier camion en DF r1
     
                                                                                        'on détermine le nb de camions qu'il faut pour le simple fret R1
                                                                                        TDFSF3R1R1 = Int(TapresT431R1 / T33R1) 'nb de tours en SF R1 du dernier camion en DF r1
     
                                                                                        'on détermine le nb de camions qu'il faut pour le simple fret R2
                                                                                        TDFSF3R1R2 = Int(TapresT431R1 / T33R2) 'nb de tours en SF R2 du dernier camion en DF r1
     
     
                                                                                        If N432R2 = 0 Then
                                                                                            X432R2 = 0
                                                                                            If N23D1 = 0 Then
                                                                                                X23D1 = 0
                                                                                                If N33R1 = 0 Then
                                                                                                    X33R1 = 0
                                                                                                    If Int((N33R2 - TDFSF3R1R2) / Maxi33R2SF) < ((N33R2 - TDFSF3R1R2) / Maxi33R2SF) Then X33R2 = Int((N33R2 - TDFSF3R1R2) / Maxi33R2SF) + 1 Else X33R2 = Int((N33R2 - TDFSF3R1R2) / Maxi33R2SF)
                                                                                                Else
                                                                                                    If Int((N33R1 - TDFSF3R1R1) / Maxi33R1SF) < ((N33R1 - TDFSF3R1R1) / Maxi33R1SF) Then X33R1 = Int((N33R1 - TDFSF3R1R1) / Maxi33R1SF) + 1 Else X33R1 = Int((N33R1 - TDFSF3R1R1) / Maxi33R1SF)
                                                                                            Else
                                                                                                If Int((N23D1 - TDFSF3R1D1) / Maxi23D1SF) < ((N23D1 - TDFSF3R1D1) / Maxi23D1SF) Then X23D1 = Int((N23D1 - TDFSF3R1D1) / Maxi23D1SF) + 1 Else X22D1 = Int((N23D1 - TDFSF3R1D1) / Maxi23D1SF)
                                                                                        Else
                                                                                            If Int((N432R2 - TDFDF3R1R2) / Maxi432) < ((N432R2 - TDFDF3R1R2) / Maxi432) Then X432R2 = Int((N432R2 - TDFDF3R1R2) / Maxi432) + 1 Else X432R2 = Int((N432R2 - TDFDF3R1R2) / Maxi432)
                                                                                        End If
     
                                                                                        If X33R2 <> 0 Then TapresT33R2 = ((X33R2 * Maxi33R2SF) - (N33R2 - TDFSF3R1R2)) * T33R2 Else TapresT33R2 = 0
     
                                                                                        If X33R1 <> 0 Then TapresT33R1 = ((X33R1 * Maxi33R1SF) - (N33R1 - TDFSF3R1R1)) * T33R1 Else TapresT33R1 = 0
     
                                                                                        If X23D1 <> 0 Then TapresT23D1 = ((X23D1 * Maxi23D1SF) - (N23D1 - TDFSF3R1D1)) * T23D1 Else TapresT23D1 = 0
     
                                                                                        If X432R2 <> 0 Then TapresT432R2 = ((X432R2 * Maxi432) - (N432R2 - TDFDF3R1R2)) * T43D1R2 Else TapresT432R2 = 0
     
                                                                                        If T43D1R2 <= TapresT432R2 And TapresT432R2 < T23D1 Then GoTo suite
     
     
                                                                                        TDFDF3R2R2 = Int(TapresT432R2 / T33R2)
                                                                                        TDFSF3R2R1 = Int(TapresT432R2 / T33R1)
                                                                                        TDFSF3R2D1 = Int(TapresT432R2 / T23D1)
     
     
                                                                                        If N23D1 = 0 Then
                                                                                            X23D1 = 0
                                                                                            If N33R1 = 0 Then
                                                                                                X33R1 = 0
                                                                                                If Int((N33R2 - TDFSF3R2R2) / Maxi33R2SF) < ((N33R2 - TDFSF3R2R2) / Maxi33R2SF) Then X33R2 = Int((N33R2 - TDFSF3R2R2) / Maxi33R2SF) + 1 Else X33R2 = Int((N33R2 - TDFSF3R2R2) / Maxi33R2SF)
                                                                                            Else
                                                                                                If Int((N33R1 - TDFSF3R2R1) / Maxi33R1SF) < ((N33R1 - TDFSF3R2R1) / Maxi33R1SF) Then X33R1 = Int((N33R1 - TDFSF3R2R1) / Maxi33R1SF) + 1 Else X33R1 = Int((N33R1 - TDFSF3R2R1) / Maxi33R1SF)
                                                                                        Else
                                                                                            If Int((N23D1 - TDFSF3R2D1) / Maxi23D1SF) < ((N23D1 - TDFSF3R2D1) / Maxi23D1SF) Then X23D1 = Int((N23D1 - TDFSF3R2D1) / Maxi23D1SF) + 1 Else X23D1 = Int((N23D1 - TDFSF3R2D1) / Maxi23D1SF)
                                                                                        End If
     
     
                                                                                        If X33R2 <> 0 Then TapresT33R2 = ((X33R2 * Maxi33R2SF) - (N33R2 - TDFSF3R2R2)) * T33R2 Else TapresT33R2 = 0
                                                                                        If X33R1 <> 0 Then TapresT33R1 = ((X33R1 * Maxi33R1SF) - (N33R1 - TDFSF3R2R1)) * T33R1 Else TapresT33R1 = 0
                                                                                        If X22D1 <> 0 Then TapresT22D1 = ((X22D1 * Maxi22D1SF) - (N22D1 - TDFSFR2D1)) * T22D1 Else TapresT22D1 = 0
     
     
                                                                                        TSFSF3D1R2 = Int(TapresT23D1 / T33R2)
                                                                                        TSFSF3D1R1 = Int(TapresT23D1 / T33R1)
     
                                                                                        If T23D1 <= TapresT23D1 And TapresT23D1 < T33R1 Then GoTo suite
     
                                                                                        If N33R1 = 0 Then
                                                                                            X33R1 = 0
                                                                                            If Int((N33R2 - TSFSF3D1R2) / Maxi33R2SF) < ((N33R2 - TSFSF3D1R2) / Maxi33R2SF) Then X33R2 = Int((N33R2 - TSFSF3D1R2) / Maxi33R2SF) + 1 Else X33R2 = Int((N33R2 - TSFSF3D1R2) / Maxi33R2SF)
                                                                                        Else
                                                                                            If Int((N33R1 - TSFSF3D1R1) / Maxi33R1SF) < ((N33R1 - TSFSF3D1R1) / Maxi33R1SF) Then X33R1 = Int((N33R1 - TSFSF3D1R1) / Maxi33R1SF) + 1 Else X33R1 = Int((N33R1 - TSFSF3D1R1) / Maxi33R1SF)
                                                                                        End If
     
                                                                                        If X33R2 <> 0 Then TapresT33R2 = ((X33R2 * Maxi33R2SF) - (N33R2 - TSFSF3D1R2)) * T33R2 Else TapresT33R2 = 0
     
                                                                                        If X33R1 <> 0 Then TapresT33R1 = ((N33R1 * Maxi33R1SF) - (N33R1 - TSFSF3D1R1)) * T33R1 Else TapresT33R1 = 0
     
     
                                                                                        If T33R1 <= TapresT33R1 And TapresT33R1 < T33R2 Then GoTo suite
     
     
                                                                                        TSFSF3R1R2 = Int(TapresT33R1 / T33R2)
     
                                                                                        If N33R2 = 0 Then
                                                                                            X33R2 = 0
                                                                                        Else
                                                                                            If Int((N33R2 - TSFSF3R1R2) / Maxi33R2SF) < ((N33R2 - TSFSF3R1R2) / Maxi33R2) Then X33R2 = Int((N33R2 - TSFSF3R1R2) / Maxi33R2) + 1 Else X33R2 = Int((N33R2 - TSFSF3R1R2) / Maxi33R2)
                                                                                        End If
                                                                                    End If
     
                                                                                    If X33R2 <> 0 Then TapresT33R2 = ((X33R2 * Maxi33R2SF) - (N33R2 - TSFSF3R1R2)) * T33R2 Else TapresT33R2 = 0
     
                                                                                    If T33R2 <= TapresT33R2 Then GoTo suite
     
                                                                                    Xtot2 = X22D1 + X32R1 + X32R2 + X421R1 + X422R2
                                                                                    Xtot3 = X23D1 + X33R1 + X33R2 + X431R1 + X432R2
     
                                                                                    'on regroupe ttes les infos concernant la ligne, les N, les A et B, Xtot2 et Xtot3
                                                                                    StrAntiDoublon = CStr(N22D1) & "-" & CStr(N32R1) & "-" & CStr(N32R2) & "-" & CStr(N421R1) & "-" & CStr(N422R2) & "-" & CStr(N42D1) & "-" & CStr(N23D1) & "-" & CStr(N33R1) & "-" & CStr(N33R2) & "-" & CStr(N431R1) & "-" & CStr(N432R2) & "-" & CStr(N43D1) & "-" & CStr(A) & "-" & CStr(B) & "-" & CStr(Xtot2) & "-" & CStr(Xtot3)
     
                                                                                    'on regarde si ces infos existent déjà
                                                                                    If DicoAntiDoublon.exists(StrAntiDoublon) Then GoTo suite
     
                                                                                    'on les rajoute puisqu'elles ne figurent pas dans le dico
                                                                                    DicoAntiDoublon.Add StrAntiDoublon, 0
     
     
     
     
     
     
                                                                                    'Si le code arrive ici c'est que notre flotte est bien occupé, donc on note les résultats dans le tableau
     
                                                                                    Cells(Ligne, "A").Value = z22D1 * w22D1
                                                                                    Cells(Ligne, "B").Value = z421R1 * w421R1
                                                                                    Cells(Ligne, "C").Value = z422R2 * w422R2
                                                                                    Cells(Ligne, "D").Value = Cells(Ligne, "B").Value + Cells(Ligne, "C").Value
                                                                                    Cells(Ligne, "E").Value = z32R1 * w32R1
                                                                                    Cells(Ligne, "F").Value = z32R2 * w32R2
                                                                                    Cells(Ligne, "G").Value = z23D1 * w23D1
                                                                                    Cells(Ligne, "H").Value = z431R1 * w431R1
                                                                                    Cells(Ligne, "I").Value = z432R2 * w432R2
                                                                                    Cells(Ligne, "J").Value = Cells(Ligne, "H").Value + Cells(Ligne, "I").Value
                                                                                    Cells(Ligne, "K").Value = z33R1 * w33R1
                                                                                    Cells(Ligne, "L").Value = z33R2 * w33R2
                                                                                    Cells(Ligne, "M").Value = A
                                                                                    Cells(Ligne, "N").Value = B
     
     
                                                                                    Cells(Ligne, "Q") = N421R1 * T42D1R1
                                                                                    Cells(Ligne, "R") = N422R2 * T42D1R2
                                                                                    Cells(Ligne, "S") = N22D1 * T22D1
                                                                                    Cells(Ligne, "T") = N32R1 * T32R1
                                                                                    Cells(Ligne, "U") = N32R2 * T32R2
                                                                                    Cells(Ligne, "AI") = N431R1 * T43D1R1
                                                                                    Cells(Ligne, "AJ") = N432R2 * T43D1R2
                                                                                    Cells(Ligne, "AK") = N23D1 * T23D1
                                                                                    Cells(Ligne, "AL") = N33R1 * T33R1
                                                                                    Cells(Ligne, "AM") = N33R2 * T33R2
     
     
                                                                                    'Xtot2 = X22 + X42 + X32
                                                                                    Cells(Ligne, "V") = X421R1
                                                                                    Cells(Ligne, "W") = TapresT421R1
                                                                                    Cells(Ligne, "X") = X422R2
                                                                                    Cells(Ligne, "Y") = TapresT422R2
                                                                                    Cells(Ligne, "Z") = X22D1
                                                                                    Cells(Ligne, "AA") = TapresT22D1
                                                                                    Cells(Ligne, "AB") = X32R1
                                                                                    Cells(Ligne, "AC") = TapresT32R1
                                                                                    Cells(Ligne, "AD") = X32R2
                                                                                    Cells(Ligne, "AE") = TapresT32R2
                                                                                    Cells(Ligne, "AF") = X421R1 + X422R2
                                                                                    Cells(Ligne, "AG") = X22D1 + X421R1 + X422R2 + X32R1 + X32R2 'Xtot2
     
     
                                                                                    'Xtot3 = X23 + X43 + X33
                                                                                    Cells(Ligne, "AN") = X431R1
                                                                                    Cells(Ligne, "AO") = TapresT431R1
                                                                                    Cells(Ligne, "AP") = X432R2
                                                                                    Cells(Ligne, "AQ") = TapresT432R2
                                                                                    Cells(Ligne, "AR") = X23D1
                                                                                    Cells(Ligne, "AS") = TapresT23D1
                                                                                    Cells(Ligne, "AT") = X33R1
                                                                                    Cells(Ligne, "AU") = TapresT23D1
                                                                                    Cells(Ligne, "AV") = X33R2
                                                                                    Cells(Ligne, "AW") = TapresT33R2
                                                                                    Cells(Ligne, "AX") = X431R1 + X432R2
                                                                                    Cells(Ligne, "AY") = X23D1 + X431R1 + X32R2 + X33R1 + X33R2 'Xtot3
     
                                                                                    Cells(Ligne, "BA") = (X22D1 + X421R1 + X422R2 + X32R1 + X32R2) * 480 + (X23D1 + X431R1 + X32R2 + X33R1 + X33R2) * 550
                                                                                    Ligne = Ligne + 1
     
                                                                                    End If
                                                                                    End If
    suite:
     
                                                                                    Next
                                                                                Next
                                                                            Next
                                                                        Next
                                                                    Next
                                                                Next
                                                            Next
                                                        Next
                                                    Next
                                                Next
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
    Next
     
    DicoAntiDoublon.RemoveAll
    Set DicoAntiDoublon = Nothing
    Application.ScreenUpdating = True
     
    End Sub
    et la trame: http://cjoint.com/?etroKqw8x2

    là apparemment le pb viendrait de Else sans If. Pour autant j'ai essayé d'incrémenter comme il fallait

  12. #52
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    Re
    J'ai eu plus de choses a faire que prévu.
    Pour ce qui est du code qui tu m'as donné, voici la correction d'une des boucles if je te laisse faire la correction sur les autres

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
                                                                                        If N432R2 = 0 Then
                                                                                            X432R2 = 0
                                                                                            If N23D1 = 0 Then
                                                                                                X23D1 = 0
                                                                                                If N33R1 = 0 Then
                                                                                                    X33R1 = 0
                                                                                                    If Int((N33R2 - TDFSF3R1R2) / Maxi33R2SF) < ((N33R2 - TDFSF3R1R2) / Maxi33R2SF) Then X33R2 = Int((N33R2 - TDFSF3R1R2) / Maxi33R2SF) + 1 Else X33R2 = Int((N33R2 - TDFSF3R1R2) / Maxi33R2SF)
                                                                                                Else
                                                                                                    If Int((N33R1 - TDFSF3R1R1) / Maxi33R1SF) < ((N33R1 - TDFSF3R1R1) / Maxi33R1SF) Then X33R1 = Int((N33R1 - TDFSF3R1R1) / Maxi33R1SF) + 1 Else X33R1 = Int((N33R1 - TDFSF3R1R1) / Maxi33R1SF)
                                                                                                End If
                                                                                            Else
                                                                                                If Int((N23D1 - TDFSF3R1D1) / Maxi23D1SF) < ((N23D1 - TDFSF3R1D1) / Maxi23D1SF) Then X23D1 = Int((N23D1 - TDFSF3R1D1) / Maxi23D1SF) + 1 Else X22D1 = Int((N23D1 - TDFSF3R1D1) / Maxi23D1SF)
                                                                                            End If
                                                                                        Else
                                                                                            If Int((N432R2 - TDFDF3R1R2) / Maxi432) < ((N432R2 - TDFDF3R1R2) / Maxi432) Then X432R2 = Int((N432R2 - TDFDF3R1R2) / Maxi432) + 1 Else X432R2 = Int((N432R2 - TDFDF3R1R2) / Maxi432)
                                                                                        End If
    Pour ce qui est de comprendre la logique du code, j'avoue avoir décroché depuis déjà la version précédente ^^, je n'ai pas suivi ce que tu as fait a l'intérieur des boucle, je ne fais donc que corrigé la syntaxe, pour ce qui est de la logique, je ne baigne pas suffisamment dedans.

    Je suis en train de regarder pour simplifier le système de boucle, peux tu éclaircir le point suivant:
    Un camion peut il faire des trajet sur des site différents? ou utilise t il toujours la même route. Je m'explique, si on prend un camion donné, est ce qu'il va toujours faire Chantier -> site1 en simple fret et chantier -> site1 -> site2 pour le double fret ? ou est ce qu'il peut faire Chantier -> site1, Chantier -> Site2, .... mon avis perso serait de toujours faire le même trajet a un camion, mais dis moi comment tu as prévu la chose.
    A++
    Qwaz

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  13. #53
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    Citation Envoyé par Emma95 Voir le message
    tu as du oublier de coller la macro!!!


    Citation Envoyé par Emma95 Voir le message
    Pour moi les camions pouvaient faire tous les types de trajet.
    C'est toi qui vois je ne sais pas comment vous fonctionnez, je trouve juste ça un chouille compliquer pour le chauffeur de se dire alors faut que je fasse 1 trajet jusqu'au site1 et revenir, puis un trajet au site1 passer au site2 pour prendre du remblai revenir au chantier,...
    Mais bon vous avez peut être un système de feuille de route qui leur permettent de pas se tromper de trajet a effectuer.
    J'essais de te faire un bout de code.
    A+

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  14. #54
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    mais comment tu prendrais en compte le double fret alors?

    j'ai réutilisé le morceau de code que tu m'as passé hier.
    Je me dmd si y a pas un pb ds le code parce qu'il s'arrête pas de tourner. Et en plus de toute façon , y a un souci parce que j'ai fais un test et j'ai trouver des valeurs négatives.


    je suis repartie avec un code beaucoup plus simple qui cherche juste à calculer le nb de camions en SF déblais, SF remblais, DF sans chercher à optimiser avec les temps restants (tapresT)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    Option Explicit 'indique les variables non déclarées
     
    Sub combinaison()
     
    Dim N22D1 As Integer, N42D1 As Integer, N23D1 As Integer, N43D1 As Integer, N32R1 As Integer, N33R1 As Integer, N32R2 As Integer, N33R2 As Integer, N421R1 As Integer, N422R2 As Integer, N431R1 As Integer, N432R2 As Integer, z22D1 As Integer, z42D1 As Integer, z23D1 As Integer, z43D1 As Integer, z32R1 As Integer, z33R1 As Integer, z32R2 As Integer, z33R2 As Integer, z421R1 As Integer, z422R2 As Integer, z431R1 As Integer, z432R2 As Integer, w22D1 As Integer, w42D1 As Integer, w23D1 As Integer, w43D1 As Integer, w32R1 As Integer, w33R1 As Integer, w32R2 As Integer, w33R2 As Integer, w421R1 As Integer, w422R2 As Integer, w431R1 As Integer, w432R2 As Integer, W As Integer, A As Integer, Aa As Integer, Ab As Integer, B1 As Integer, Ba1 As Integer, Bb1 As Integer, B2 As Integer, Ba2 As Integer, Bb2 As Integer
    Dim T22D1 As Single, s22D1 As Single, T32R1 As Single, s32R1 As Single, T32R2 As Single, s32R2 As Single, T42D1R1 As Single, s421R1 As Single, T42D1R2 As Single, s422R2 As Single, T23D1 As Single, s23D1 As Single, T33R1 As Single, s33R1 As Single, T33R2 As Single, s33R2 As Single, T43D1R1 As Single, s431R1 As Single, T43D1R2 As Single, s432R2 As Single
    Dim X22D1 As Integer, X42D1 As Integer, X32R1 As Integer, X32R2 As Integer, X421R1 As Integer, X422R2 As Integer, X23D1 As Integer, X43D1 As Integer, X33R1 As Integer, X33R2 As Integer, X431R1 As Integer, X432R2 As Integer, Xtot2 As Integer, Xtot3 As Integer
    Dim maxi As Integer, Maxi22D1SF As Integer, Maxi32R1SF As Integer, Maxi32R2SF As Integer, Maxi421DF As Integer, Maxi422DF As Integer, Maxi23D1SF As Integer, Maxi33R1SF As Integer, Maxi33R2SF As Integer, Maxi431DF As Integer, Maxi432DF As Integer
    Dim Ligne As Long, PT As Integer
    Dim a22D1 As Integer, a42D1 As Integer, a23D1 As Integer, a43D1 As Integer, a32R1 As Integer, a32R2 As Integer, a421R1 As Integer, a422R2 As Integer, a33R1 As Integer, a33R2 As Integer, a431R1 As Integer, a432R2 As Integer
    Dim DicoAntiDoublon As New dictionary, StrAntiDoublon As String
     
    'On stop le refraichissement pour eviter le scintillement et gagner en vitesse
    Application.ScreenUpdating = False
     
    [A11.BA65536].ClearContents
    [M2].ClearContents
    [O2].ClearContents
    [Q2].ClearContents
    [S2].ClearContents
    [U2].ClearContents
    [M4].ClearContents
    [O4].ClearContents
    [Q4].ClearContents
    [S4].ClearContents
    [U4].ClearContents
     
     
    W = [A3] 'nb max camion/jour
    Ab = [C3] 'rdt/jour en déblais
    Aa = [C1] 'rdt limite/jour en déblais
    Bb1 = [E3] 'rdt/jour en remblais
    Ba1 = [E1] 'rdt limite/jour en remblais
    Bb2 = [E7]
    Ba2 = [E5]
    T22D1 = [G1]
    T42D1R1 = [G3]
    T32R1 = [G5]
    T42D1R2 = [G7]
    T32R2 = [G9]
    T23D1 = [I1]
    T43D1R1 = [I3]
    T33R1 = [I5]
    T43D1R2 = [I7]
    T33R2 = [I9]
    maxi = [A5] 'nb heures travaillées max
    Ligne = 11
     
    Maxi22D1SF = Int(maxi / T22D1) 'nb maxi de tours/camions/jour en SF(8m3) en D1
    Maxi32R1SF = Int(maxi / T32R1) 'nb maxi de tours/camions/jour en SF(8m3) en R1
    Maxi32R2SF = Int(maxi / T32R2) 'nb maxi de tours/camions/jour en SF(8m3) en R2
    Maxi421DF = Int(maxi / T42D1R1) 'nb maxi de tours/camions/jour en DF(8m3) D1/R1
    Maxi422DF = Int(maxi / T42D1R2) 'nb maxi de tours/camion/jour en DF(8m3) DI/R2
    'Maxi42DF = Maxi421DF + Maxi422DF 'pb car sur une journée boucle for?
     
    Maxi23D1SF = Int(maxi / T23D1) 'nb maxi de tours/camions/jour en SF(10m3) en D1
    Maxi33R1SF = Int(maxi / T33R1) 'nb maxi de tours/camions/jour en SF(10m3) en R1
    Maxi33R2SF = Int(maxi / T33R2) 'nb maxi de tours/camions/jour en SF(10m3) en R2
    Maxi431DF = Int(maxi / T43D1R1) 'nb maxi de tours/camions/jour en DF(10m3) D1/R1
    Maxi432DF = Int(maxi / T43D1R2) 'nb maxi de tours/camion/jour en DF(10m3) DI/R2
    'Maxi43DF = Maxi431DF + Maxi432DF 'pb car sur une journée
     
     
     
    'Il vaut mieux mettre ca ici plutot que de le repeter a chaque boucle
    [M2] = Maxi22D1SF
    [O2] = Maxi32R1SF
    [Q2] = Maxi32R2SF
    [S2] = Maxi421DF
    [U2] = Maxi422DF
    [M4] = Maxi23D1SF
    [O4] = Maxi33R1SF
    [Q4] = Maxi33R2SF
    [S4] = Maxi431DF
    [U4] = Maxi432DF
     
     
     
    For w421R1 = 0 To W
        For z421R1 = 1 To Maxi421DF
            For w422R2 = 0 To W - w421R1
                For z422R2 = 1 To Maxi422DF
                    For w22D1 = 0 To W - (w421R1 + w422R2)
                        For z22D1 = 1 To Maxi22D1SF
                            For w32R1 = 0 To W - (w421R1 + w422R2 + w22D1)
                                For z32R1 = 1 To Maxi32R1SF
                                    For w32R2 = 0 To W - (w421R1 + w422R2 + w22D1 + w32R1)
                                        For z32R2 = 1 To Maxi32R2SF
                                             For w431R1 = 1 To W - (w421R1 + w422R2 + w22D1 + w32R1 + w32R2)
                                                For z431R1 = 1 To Maxi431DF
                                                    For w432R2 = 0 To W - (w421R1 + w422R2 + w22D1 + w32R1 + w32R2 + w431R1)
                                                        For z432R2 = 1 To Maxi432DF
                                                            For w23D1 = 0 To W - (w421R1 + w422R2 + w22D1 + w32R1 + w32R2 + w431R1 + w432R2)
                                                                For z23D1 = 1 To Maxi23D1SF
                                                                    For w33R1 = 0 To W - (w421R1 + w422R2 + w22D1 + w32R1 + w32R2 + w431R1 + w432R2 + w23D1)
                                                                        For z33R1 = 1 To Maxi33R1SF
                                                                            For w33R2 = 0 To W - (w421R1 + w422R2 + w22D1 + w32R1 + w32R2 + w431R1 + w432R2 + w23D1 + w33R1)
                                                                                For z33R2 = 1 To Maxi33R2SF
     
     
     
     
                                                                                A = z22D1 * w22D1 * 8 + (z421R1 * w421R1 + z422R2 * w422R2) * 8 + z23D1 * w23D1 * 10 + (z431R1 * w431R1 + z432R2 * w432R2) * 10
                                                                                B1 = z32R1 * w32R1 * 8 + (z421R1 * w421R1) * 8 + z33R1 * w33R1 * 10 + (z431R1 * w431R1) * 10
                                                                                B2 = z32R2 * w32R2 * 8 + z422R2 * w422R2 * 8 + z33R2 * w33R2 * 10 + z432R2 * w432R2 * 10
                                                                                If (Aa < A And A <= Ab) And (Ba1 < B1 And B1 <= Bb1) And (Ba2 < B2 And B2 <= Bb2) Then
                                                                                    If ((z421R1 * T42D1R1 + z422R2 * T42D1R2) > maxi) And ((z431R1 * T43D1R1 + z432R2 * T43D1R2) > maxi) Then GoTo suite
     
                                                                                    'le temps passé en DF ne doit pas excéder 8h
                                                                                    'z421R1 * T42D1R1 + z422R2 * T42D1R2 <=Maxi
                                                                                    'z431R1 * T43D1R1 + z432R2 * T43D1R2 <=Maxi
     
                                                                                    N22D1 = z22D1 * w22D1
                                                                                    N421R1 = z421R1 * w421R1
                                                                                    N422R2 = z422R2 * w422R2
                                                                                    N32R1 = z32R1 * w32R1
                                                                                    N32R2 = z32R2 * w32R2
                                                                                    N42D1 = N421R1 + N422R2
     
                                                                                    N23D1 = z23D1 * w23D1
                                                                                    N431R1 = z431R1 * w431R1
                                                                                    N432R2 = z432R2 * w432R2
                                                                                    N33R1 = z33R1 * w33R1
                                                                                    N33R2 = z33R2 * w33R2
                                                                                    N43D1 = N431R1 + N432R2
     
     
     
                                                                                    s22D1 = N22D1 * T22D1
                                                                                    s421R1 = N421R1 * T42D1R1
                                                                                    s422R2 = N422R2 * T42D1R2
                                                                                    s32R1 = N32R1 * T32R1
                                                                                    s32R2 = N32R2 * T32R2
     
                                                                                    s23D1 = N23D1 * T23D1
                                                                                    s431R1 = N431R1 * T43D1R1
                                                                                    s432R2 = N432R2 * T43D1R2
                                                                                    s33R1 = N33R1 * T33R1
                                                                                    s33R2 = N33R2 * T33R2
     
                                                                                    'initialisation des valeurs de X
                                                                                    X22D1 = 0
                                                                                    X42D1 = 0
                                                                                    X421R1 = 0
                                                                                    X422R2 = 0
                                                                                    X32R1 = 0
                                                                                    X32R2 = 0
                                                                                    X23D1 = 0
                                                                                    X43D1 = 0
                                                                                    X431R1 = 0
                                                                                    X432R2 = 0
                                                                                    X33R1 = 0
                                                                                    X33R2 = 0
     
     
     
     
     
                                                                                    'a) si N22D1=N421R1=N422R2=N32R1=N32R2=0, on va à la ligne suivante
                                                                                    If Not (N22D1 = 0 And N421R1 = 0 And N422R2 = 0 And N32R1 = 0 And N32R2 = 0) Then
     
     
                                                                                        'on détermine le nombre de camions qu'il faut pour le double fret D1/R1
     
                                                                                        If Int(N421R1 / Maxi421DF) < N421R1 / Maxi421DF Then X421R1 = Int(N421R1 / Maxi421DF) + 1 Else X421R1 = N421R1 / Maxi421DF
     
                                                                                        If Int((N422R2) / Maxi422DF) < ((N422R2) / Maxi422DF) Then X422R2 = Int((N422R2) / Maxi422DF) + 1 Else X422R2 = Int((N422R2) / Maxi422DF)
     
     
                                                                                        If Int((N22D1) / Maxi22D1SF) < ((N22D1) / Maxi22D1SF) Then X22D1 = Int((N22D1) / Maxi22D1SF) + 1 Else X22D1 = Int((N22D1) / Maxi22D1SF)
     
                                                                                        If Int((N32R1) / Maxi32R1SF) < ((N32R1) / Maxi32R1SF) Then X32R1 = Int((N32R1) / Maxi32R1SF) + 1 Else X32R1 = Int((N32R1) / Maxi32R1SF)
     
                                                                                        If Int((N32R2) / Maxi32R2SF) < ((N32R2) / Maxi32R2SF) Then X32R2 = Int((N32R2) / Maxi32R2SF) + 1 Else X32R2 = Int((N32R2) / Maxi32R2SF)
                                                                                        End If
                                                                                    End If
     
     
                                                                                    'b) si N23D1=N431R1=N432R2=N33R1=N33R2=0, on va à la ligne suivante
                                                                                    If Not (N23D1 = 0 And N431R1 = 0 And N432R2 = 0 And N33R1 = 0 And N33R2 = 0) Then
     
     
                                                                                        'on détermine le nombre de camions qu'il faut pour le double fret D1/R1
     
                                                                                        If Int(N431R1 / Maxi431DF) < N431R1 / Maxi431DF Then X431R1 = Int(N431R1 / Maxi431DF) + 1 Else X431R1 = N431R1 / Maxi431DF
     
     
                                                                                        If Int((N432R2) / Maxi432DF) < ((N432R2) / Maxi432DF) Then X432R2 = Int((N432R2) / Maxi432DF) + 1 Else X432R2 = Int((N432R2) / Maxi432DF)
     
                                                                                        If Int((N23D1) / Maxi23D1SF) < ((N23D1) / Maxi23D1SF) Then X23D1 = Int((N23D1) / Maxi23D1SF) + 1 Else X23D1 = Int((N23D1) / Maxi23D1SF)
     
                                                                                        If Int((N33R1) / Maxi33R1SF) < ((N33R1) / Maxi33R1SF) Then X33R1 = Int((N33R1) / Maxi33R1SF) + 1 Else X33R1 = Int((N33R1) / Maxi33R1SF)
     
                                                                                        If Int((N33R2) / Maxi33R2SF) < ((N33R2) / Maxi33R2SF) Then X33R2 = Int((N33R2) / Maxi33R2SF) + 1 Else X33R2 = Int((N33R2) / Maxi33R2SF)
                                                                                        End If
     
                                                                                    End If
     
     
     
     
     
                                                                                    Xtot2 = X22D1 + X32R1 + X32R2 + X421R1 + X422R2
                                                                                    Xtot3 = X23D1 + X33R1 + X33R2 + X431R1 + X432R2
     
                                                                                    'on regroupe ttes les infos concernant la ligne, les N, les A et B1 et B2, Xtot2 et Xtot3
                                                                                    StrAntiDoublon = CStr(N421R1) & "-" & CStr(N422R2) & "-" & CStr(N22D1) & "-" & CStr(N32R1) & "-" & CStr(N32R2) & "-" & CStr(N42D1) & "-" & CStr(N431R1) & "-" & CStr(N432R2) & "-" & CStr(N23D1) & "-" & CStr(N33R1) & "-" & CStr(N33R2) & "-" & CStr(N43D1) & "-" & CStr(A) & "-" & CStr(B1) & "-" & CStr(B2) & "-" & CStr(Xtot2) & "-" & CStr(Xtot3)
     
                                                                                    'on regarde si ces infos existent déjà
                                                                                    If DicoAntiDoublon.exists(StrAntiDoublon) Then GoTo suite
     
                                                                                    'on les rajoute puisqu'elles ne figurent pas dans le dico
                                                                                    DicoAntiDoublon.Add StrAntiDoublon, 0
     
     
     
     
     
     
                                                                                    'Si le code arrive ici c'est que notre flotte est bien occupé, donc on note les résultats dans le tableau
     
                                                                                    Cells(Ligne, "A").Value = z421R1 * w421R1
                                                                                    Cells(Ligne, "B").Value = z422R2 * w422R2
                                                                                    Cells(Ligne, "C").Value = z22D1 * w22D1
                                                                                    Cells(Ligne, "D").Value = z32R1 * w32R1
                                                                                    Cells(Ligne, "E").Value = z32R2 * w32R2
                                                                                    Cells(Ligne, "F").Value = Cells(Ligne, "B").Value + Cells(Ligne, "C").Value
                                                                                    Cells(Ligne, "G").Value = z431R1 * w431R1
                                                                                    Cells(Ligne, "H").Value = z432R2 * w432R2
                                                                                    Cells(Ligne, "I").Value = z23D1 * w23D1
                                                                                    Cells(Ligne, "J").Value = z33R1 * w33R1
                                                                                    Cells(Ligne, "K").Value = z33R2 * w33R2
                                                                                    Cells(Ligne, "L").Value = Cells(Ligne, "H").Value + Cells(Ligne, "I").Value
                                                                                    Cells(Ligne, "M").Value = A
                                                                                    Cells(Ligne, "N").Value = B1
                                                                                    Cells(Ligne, "O").Value = B2
     
     
                                                                                    Cells(Ligne, "Q") = N421R1 * T42D1R1
                                                                                    Cells(Ligne, "R") = N422R2 * T42D1R2
                                                                                    Cells(Ligne, "S") = N22D1 * T22D1
                                                                                    Cells(Ligne, "T") = N32R1 * T32R1
                                                                                    Cells(Ligne, "U") = N32R2 * T32R2
                                                                                    Cells(Ligne, "AI") = N431R1 * T43D1R1
                                                                                    Cells(Ligne, "AJ") = N432R2 * T43D1R2
                                                                                    Cells(Ligne, "AK") = N23D1 * T23D1
                                                                                    Cells(Ligne, "AL") = N33R1 * T33R1
                                                                                    Cells(Ligne, "AM") = N33R2 * T33R2
     
     
                                                                                    'Xtot2 = X22 + X42 + X32
                                                                                    Cells(Ligne, "V") = X421R1
     
                                                                                    Cells(Ligne, "X") = X422R2
     
                                                                                    Cells(Ligne, "Z") = X22D1
     
                                                                                    Cells(Ligne, "AB") = X32R1
     
                                                                                    Cells(Ligne, "AD") = X32R2
     
                                                                                    Cells(Ligne, "AF") = X421R1 + X422R2
                                                                                    Cells(Ligne, "AG") = X22D1 + X421R1 + X422R2 + X32R1 + X32R2 'Xtot2
     
     
                                                                                    'Xtot3 = X23 + X43 + X33
                                                                                    Cells(Ligne, "AN") = X431R1
     
                                                                                    Cells(Ligne, "AP") = X432R2
     
                                                                                    Cells(Ligne, "AR") = X23D1
     
                                                                                    Cells(Ligne, "AT") = X33R1
     
                                                                                    Cells(Ligne, "AV") = X33R2
     
                                                                                    Cells(Ligne, "AX") = X431R1 + X432R2
                                                                                    Cells(Ligne, "AY") = X23D1 + X431R1 + X32R2 + X33R1 + X33R2 'Xtot3
     
                                                                                    Cells(Ligne, "BA") = (X22D1 + X421R1 + X422R2 + X32R1 + X32R2) * 480 + (X23D1 + X431R1 + X32R2 + X33R1 + X33R2) * 550
                                                                                    Ligne = Ligne + 1
     
     
                                                                                End If
     
    suite:
     
     
                                                                                Next
                                                                            Next
                                                                        Next
                                                                    Next
                                                                Next
                                                            Next
                                                        Next
                                                    Next
                                                Next
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
    Next
     
    DicoAntiDoublon.RemoveAll
    Set DicoAntiDoublon = Nothing
    Application.ScreenUpdating = True
     
    End Sub
    j'ai rajouté un troisième rendement parce que celui du remblais 2 n'est pas forcément le même que celui du Remblais1.



    bien sur ça ne fonctionne. comme d'hab, mes if ... end if doivent y etre pour bcp

  15. #55
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    Je pense avoir trouver un structure qui irait pas mal, mais il va me falloir un peu de temps pour la mettre en place.

    bien sur ça ne fonctionne. comme d'hab, mes if ... end if doivent y etre pour bcp
    Alors pour que tu essais de résoudre ton problème avec les boucles if, suis le raisonnement suivant:

    Si tu écris ta boucle if sur 1 seule et unique ligne:
    exemple:
    a=25
    b=32
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    'Structure if ... then
    if a<3 then c =12
    'structure if ... then ... else
    if b = a then d=2 else d=3
    1. Pas d'indentation a gerer
    2. pas de end if
    3. tu ne peux utiliser que la structure "if ... then" ou "if ... then ... else"



    maintenant si tu veux exécuter plusieurs ligne de code a l'intérieur de ta boucle if, tu es obliger d'utiliser des structure sur plusieurs lignes

    exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    if a= 2 then
       c = 2
       d = 6
    elseif a = 3 and b = 12 then
       c = 3
       d = 2
    elseif a = 6 or b = 5 then
       c = 5
    else 
       c = 8
    end if
    Les règles a suivre:
    1. a chaque fois que tu écris "if ... then" ou "ElseIf ... then" ou "Else", les lignes qui doivent être exécuter sont décalées d'une tabulation vers la droite
    2. lorsque tu termines ta boucle tu utilise "End If"


    Si tu suis ces quelques règles, tu devrais pouvoir organiser ton code comme il faut, gardes a l'esprit que si ton indentation est bien faite, il n'est pas possible comme je l'ai vu dans un de tes code d'avoir 2 "end if" ou 2 "next" l'un en dessous de l'autre avec la même indentation, c'est un coup a prendre a près tu le feras machinalement si tu continues a faire de la programmation.

    j'essais de te mettre un code en ligne pour demain matin.

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  16. #56
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    En jetant un coup d'oeil rapide, tu as 2 endroits fait pareil et qui son mal écrit
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
        'b) si N23D1=N431R1=N432R2=N33R1=N33R2=0, on va à la ligne suivante
                                                                                    If Not (N23D1 = 0 And N431R1 = 0 And N432R2 = 0 And N33R1 = 0 And N33R2 = 0) Then
     
     
                                                                                        'on détermine le nombre de camions qu'il faut pour le double fret D1/R1
     
                                                                                        If Int(N431R1 / Maxi431DF) < N431R1 / Maxi431DF Then X431R1 = Int(N431R1 / Maxi431DF) + 1 Else X431R1 = N431R1 / Maxi431DF
     
     
                                                                                        If Int((N432R2) / Maxi432DF) < ((N432R2) / Maxi432DF) Then X432R2 = Int((N432R2) / Maxi432DF) + 1 Else X432R2 = Int((N432R2) / Maxi432DF)
     
                                                                                        If Int((N23D1) / Maxi23D1SF) < ((N23D1) / Maxi23D1SF) Then X23D1 = Int((N23D1) / Maxi23D1SF) + 1 Else X23D1 = Int((N23D1) / Maxi23D1SF)
     
                                                                                        If Int((N33R1) / Maxi33R1SF) < ((N33R1) / Maxi33R1SF) Then X33R1 = Int((N33R1) / Maxi33R1SF) + 1 Else X33R1 = Int((N33R1) / Maxi33R1SF)
     
                                                                                        If Int((N33R2) / Maxi33R2SF) < ((N33R2) / Maxi33R2SF) Then X33R2 = Int((N33R2) / Maxi33R2SF) + 1 Else X33R2 = Int((N33R2) / Maxi33R2SF)
                                                                                        End If 'Ce "End If" est de trop, il n'a aucune boucle if a fermer
     
                                                                                    End If

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  17. #57
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    merci.

    j'ai relancé avec la correction. Et j'ai droit à un écran tout blanc

    merci ça serait super si t'arrivais à trouver qqch.

    Ce projet va me faire craquer!!!!!!

    le truc compliqué c'est qu'on peut avoir à gérer plusieurs déblais et plusieurs remblais.

    faudra surement mettre une limite: pas plus de tant de types de déblais idem pour les remblais

  18. #58
    Rédacteur/Modérateur


    Homme Profil pro
    Formateur et développeur chez EXCELLEZ.net
    Inscrit en
    Novembre 2003
    Messages
    19 125
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur et développeur chez EXCELLEZ.net
    Secteur : Enseignement

    Informations forums :
    Inscription : Novembre 2003
    Messages : 19 125
    Billets dans le blog
    131
    Par défaut
    Bonjour.

    Pour moi, ton projet est dans le mur depuis longtemps

    - Définir ce que tu dois réaliser, en français
    - Réfléchir sur les moyens d'y parvenir, en français
    - Créer un organigramme clair, qui permet de découper le projet en petits morceaux testables, vérifiables, qu'il "suffira" d'imbriquer et relier les uns aux autres
    - Travailler avec des des fonctions les plus petites et découpées possible
    - Utiliser Excel avant d'utiliser VBA (plages nommées, notamment) pour alléger et simplifier le code et en garantir la maintenance et la pérennité
    - Utiliser des noms de variables qui "parlent"
    - ...

    On est loin de tout cela ici. Désolé si je te donne l'impression d'être dur, mais j'ai lu tous les messages de cette discussion et je peux garantir que, au final, tu auras une usine à gaz qui te pètera à la figure.

    Mon conseil : Reprendre tout depuis le début en suivant les étapes décrites plus haut, en n'ayant pas "les yeux plus grands que le ventre", et en découpant (c'est impératif si tu veux t'en sortir) ton projet en modules simples et testables.
    "Plus les hommes seront éclairés, plus ils seront libres" (Voltaire)
    ---------------
    Mes billets de blog sur DVP
    Mes remarques et critiques sont purement techniques. Ne les prenez jamais pour des attaques personnelles...
    Pensez à utiliser les tableaux structurés. Ils vous simplifieront la vie, tant en Excel qu'en VBA ==> mon tuto
    Le VBA ne palliera jamais une mauvaise conception de classeur ou un manque de connaissances des outils natifs d'Excel...
    Ce ne sont pas des bonnes pratiques parce que ce sont les miennes, ce sont les miennes parce que ce sont des bonnes pratiques
    VBA pour Excel? Pensez D'ABORD en EXCEL avant de penser en VBA...
    ---------------

  19. #59
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 40
    Par défaut
    je suis tout à fait d'accord avec vous: c'est une usine à gaz!!!

    je vais essayer de réorganiser tout ça, sachant que le calcul du nombre de camions n'est déjà qu'une partie de mon projet.

    Merci

    Qwazerty,

    je suis repartie avec ton idée: les camions qui s'occupent des déblais ne s'occuperont pas des remblais.

    je suis toujours avec une seul type de déblais et 2 type de remblais

    1) calcul du nb de camions en SF déblais et du temps restant du dernier camion

    2) s'il y a des tours à faire en DF avec R1, je calcule le nombre de camions qu'il faut en DF R1 et le temps restant

    je calcule le nombre de camions en SF R1
    je calcule le nombre de camions en en DF R2 puis celui en SFR2

    ou alors s'il n'y a pas de tours en DF R1, je calcule le nombre de camions en DF R2 puis le nombre de camions en SF R2
    et enfin le nombre de camions en SFR1.


    La macro se lance. Mais elle tourne indéfiniment avec un fond plan. Est-ce que c'est normal qu'il lui faut autant de temps pour chercher???


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    Option Explicit 'indique les variables non déclarées
     
    Sub combinaison()
     
    Dim N22D1 As Integer, N42D1 As Integer, N32R1 As Integer, N32R2 As Integer, N421R1 As Integer, N422R2 As Integer, N23D1 As Integer, N43D1 As Integer, N33R1 As Integer, N33R2 As Integer, N431R1 As Integer, N432R2 As Integer, z22D1 As Integer, z42D1 As Integer, z32R1 As Integer, z32R2 As Integer, z421R1 As Integer, z422R2 As Integer, w22D1 As Integer, w42D1 As Integer, w32R1 As Integer, w32R2 As Integer, w421R1 As Integer, w422R2 As Integer, z23D1 As Integer, z43D1 As Integer, z33R1 As Integer, z33R2 As Integer, z431R1 As Integer, z432R2 As Integer, w23D1 As Integer, w43D1 As Integer, w33R1 As Integer, w33R2 As Integer, w431R1 As Integer, w432R2 As Integer, W As Integer, A As Integer, Aa As Integer, Ab As Integer, B1 As Integer, B2 As Integer, Ba1 As Integer, Bb1 As Integer, Ba2 As Integer, Bb2 As Integer
    Dim T22D1 As Single, s22D1 As Single, T32R1 As Single, s32R1 As Single, T32R2 As Single, s32R2 As Single, T42D1R1 As Single, s421R1 As Single, T42D1R2 As Single, s422R2 As Single, T23D1 As Single, s23D1 As Single, T33R1 As Single, s33R1 As Single, T33R2 As Single, s33R2 As Single, T43D1R1 As Single, s431R1 As Single, T43D1R2 As Single, s432R2 As Single
    Dim X22D1 As Integer, X42D1 As Integer, X32R1 As Integer, X32R2 As Integer, X421R1 As Integer, X422R2 As Integer, Xtot2 As Integer, X23D1 As Integer, X43D1 As Integer, X33R1 As Integer, X33R2 As Integer, X431R1 As Integer, X432R2 As Integer, Xtot3 As Integer
    Dim maxi As Integer, Maxi22D1SF As Integer, Maxi32R1SF As Integer, Maxi32R2SF As Integer, Maxi421 As Integer, Maxi422 As Integer, TapresT22D1 As Single, TapresT32R1 As Single, TapresT32R2 As Single, TapresT421 As Single, TapresT422 As Single, TSFDF2D1 As Integer, TDFSF2R1 As Integer, TDFSF2R2 As Integer, Maxi23D1SF As Integer, Maxi33R1SF As Integer, Maxi33R2SF As Integer, Maxi431 As Integer, Maxi432 As Integer, TapresT23D1 As Single, TapresT33R1 As Single, TapresT33R2 As Single, TapresT431 As Single, TapresT432 As Single, TSFDF3D1 As Integer, TDFSF3R1 As Integer, TDFSF3R2 As Integer
    Dim Ligne As Long, PT As Integer
    Dim a22D1 As Integer, a42D1 As Integer, a32R1 As Integer, a32R2 As Integer, a421R1 As Integer, a422R2 As Integer, a23D1 As Integer, a43D1 As Integer, a33R1 As Integer, a33R2 As Integer, a431R1 As Integer, a432R2 As Integer
    Dim DicoAntiDoublon As New dictionary, StrAntiDoublon As String
     
    'On stop le refraichissement pour eviter le scintillement et gagner en vitesse
    Application.ScreenUpdating = False
     
    [A11.BA65536].ClearContents
    [M2].ClearContents
    [O2].ClearContents
    [Q2].ClearContents
    [S2].ClearContents
    [U2].ClearContents
    [M4].ClearContents
    [O4].ClearContents
    [Q4].ClearContents
    [S4].ClearContents
    [U4].ClearContents
     
     
    W = [A3] 'nb max camion/jour
    Ab = [C3] 'rdt/jour en déblais
    Aa = [C1] 'rdt limite/jour en déblais
    Bb1 = [E3] 'rdt/jour en remblais
    Ba1 = [E1] 'rdt limite/jour en remblais
    Bb2 = [E8]
    Ba2 = [E6]
    T22D1 = [G1]
    T42D1R1 = [G3]
    T32R1 = [G5]
    T42D1R2 = [G7]
    T32R2 = [G9]
     
    T23D1 = [I1]
    T43D1R1 = [I3]
    T33R1 = [I5]
    T43D1R2 = [I7]
    T33R2 = [I9]
     
    maxi = [A5] 'nb heures travaillées max
    Ligne = 11
     
    Maxi22D1SF = Int(maxi / T22D1) 'nb maxi de tours/camions/jour en SF(8m3) en D1
    Maxi32R1SF = Int(maxi / T32R1) 'nb maxi de tours/camions/jour en SF(8m3) en R1
    Maxi32R2SF = Int(maxi / T32R2) 'nb maxi de tours/camions/jour en SF(8m3) en R2
    Maxi421 = Int(maxi / T42D1R1) 'nb maxi de tours/camions/jour en DF(8m3) D1/R1
    Maxi422 = Int(maxi / T42D1R2) 'nb maxi de tours/camion/jour en DF(8m3) DI/R2
    'Maxi42DF = Maxi421DF + Maxi422DF 'pb car sur une journée boucle for?
     
    Maxi23D1SF = Int(maxi / T23D1) 'nb maxi de tours/camions/jour en SF(10m3) en D1
    Maxi33R1SF = Int(maxi / T33R1) 'nb maxi de tours/camions/jour en SF(10m3) en R1
    Maxi33R2SF = Int(maxi / T33R2) 'nb maxi de tours/camions/jour en SF(10m3) en R2
    Maxi431 = Int(maxi / T43D1R1) 'nb maxi de tours/camions/jour en DF(10m3) D1/R1
    Maxi432 = Int(maxi / T43D1R2) 'nb maxi de tours/camion/jour en DF(10m3) DI/R2
    'Maxi43DF = Maxi431 + Maxi432DF 'pb car sur une journée
     
     
     
    'Il vaut mieux mettre ca ici plutot que de le repeter a chaque boucle
    [M2] = Maxi22D1SF
    [O2] = Maxi32R1SF
    [Q2] = Maxi32R2SF
    [S2] = Maxi421
    [U2] = Maxi422
    [M4] = Maxi23D1SF
    [O4] = Maxi33R1SF
    [Q4] = Maxi33R2SF
    [S4] = Maxi431
    [U4] = Maxi432
     
     
    For w22D1 = 0 To W
        For z22D1 = 1 To Maxi22D1SF
            For w421R1 = 0 To W - (w22D1)
                For z421R1 = 1 To Maxi421
                    For w422R2 = 0 To W - (w22D1 + w421R1)
                        For z422R2 = 1 To Maxi422
                            For w32R1 = 0 To W - (w22D1 + w421R1 + w422R2)
                                For z32R1 = 1 To Maxi32R1SF
                                    For w32R2 = 0 To W - (w22D1 + w421R1 + w422R2 + w32R1)
                                        For z32R2 = 1 To Maxi32R2SF
                                            For w23D1 = 0 To W - (w22D1 + w421R1 + w422R2 + w32R1 + w32R2)
                                                For z23D1 = 1 To Maxi23D1SF
                                                    For w431R1 = 1 To W - (w22D1 + w421R1 + w422R2 + w32R1 + w32R2 + w23D1)
                                                        For z431R1 = 1 To Maxi431
                                                            For w432R2 = 0 To W - (w22D1 + w421R1 + w422R2 + w32R1 + w32R2 + w23D1 + w431R1)
                                                                For z432R2 = 1 To Maxi432
                                                                    For w33R1 = 0 To W - (w22D1 + w421R1 + w422R2 + w32R1 + w32R2 + w23D1 + w431R1 + w432R2)
                                                                        For z33R1 = 1 To Maxi33R1SF
                                                                            For w33R2 = 0 To W - (w22D1 + w421R1 + w422R2 + w32R1 + w32R2 + w23D1 + w431R1 + w432R2 + w33R1)
                                                                                For z33R2 = 1 To Maxi33R2SF
     
     
     
     
                                                                                A = z22D1 * w22D1 * 8 + (z421R1 * w421R1 + z422R2 * w422R2) * 8 + z23D1 * w23D1 * 10 + (z431R1 * w431R1 + z432R2 * w432R2) * 10
                                                                                B1 = z32R1 * w32R1 * 8 + (z421R1 * w421R1) * 8 + z33R1 * w33R1 * 10 + (z431R1 * w431R1) * 10
                                                                                B2 = z32R2 * w32R2 * 8 + z422R2 * w422R2 * 8 + z33R2 * w33R2 * 10 + z432R2 * w432R2 * 10
     
                                                                                If (Aa < A And A <= Ab) And (Ba1 < B1 And B1 <= Bb1) And (Ba2 < B2 And B2 <= Bb2) Then
                                                                                    If ((z421R1 * T42D1R1 + z422R2 * T42D1R2) <= maxi) And ((z431R1 * T43D1R1 + z432R2 * T43D1R2) <= maxi) Then 'est-ce que c'est bien positionné???
     
     
                                                                                'z421R1 * T42D1R1 + z422R2 * T42D1R2 <=Maxi
                                                                                'z431R1 * T43D1R1 + z432R2 * T43D1R2 <=Maxi
     
                                                                                N22D1 = z22D1 * w22D1
                                                                                N421R1 = z421R1 * w421R1
                                                                                N422R2 = z422R2 * w422R2
                                                                                N32R1 = z32R1 * w32R1
                                                                                N32R2 = z32R2 * w32R2
                                                                                N42D1 = N421R1 + N422R2
     
                                                                                N23D1 = z23D1 * w23D1
                                                                                N431R1 = z431R1 * w431R1
                                                                                N432R2 = z432R2 * w432R2
                                                                                N33R1 = z33R1 * w33R1
                                                                                N33R2 = z33R2 * w33R2
                                                                                N43D1 = N431R1 + N432R2
     
     
     
                                                                                s22D1 = N22D1 * T22D1
                                                                                s421R1 = N421R1 * T42D1R1
                                                                                s422R2 = N422R2 * T42D1R2
                                                                                s32R1 = N32R1 * T32R1
                                                                                s32R2 = N32R2 * T32R2
     
                                                                                s23D1 = N23D1 * T23D1
                                                                                s431R1 = N431R1 * T43D1R1
                                                                                s432R2 = N432R2 * T43D1R2
                                                                                s33R1 = N33R1 * T33R1
                                                                                s33R2 = N33R2 * T33R2
     
                                                                                'initialisation des valeurs de X
                                                                                X22D1 = 0
                                                                                X42D1 = 0
                                                                                X421R1 = 0
                                                                                X422R2 = 0
                                                                                X32R1 = 0
                                                                                X32R2 = 0
                                                                                X23D1 = 0
                                                                                X43D1 = 0
                                                                                X431R1 = 0
                                                                                X432R2 = 0
                                                                                X33R1 = 0
                                                                                X33R2 = 0
     
                                                                                'initialisation des temps restants
                                                                                TapresT22D1 = 0
                                                                                TapresT421 = 0
                                                                                TapresT422 = 0
                                                                                TapresT32R1 = 0
                                                                                TapresT32R2 = 0
                                                                                TapresT23D1 = 0
                                                                                TapresT431 = 0
                                                                                TapresT432 = 0
                                                                                TapresT33R1 = 0
                                                                                TapresT33R2 = 0
     
     
     
                                                                                'a) si N22D1=N421R1=N422R2=N32R1=N32R2=0, on va à la ligne suivante
                                                                                If Not (N22D1 = 0 And N421R1 = 0 And N422R2 = 0 And N32R1 = 0 And N32R2 = 0) Then
     
     
                                                                                    'on détermine le nombre de camions qu'il faut pour le double fret D1/R1
                                                                                    'on cherche X421R1 tq Maxi*(X421R1-1)<=s421R1<=Maxi*X421R1
                                                                                    If Int(N22D1 / Maxi22D1SF) < N22D1 / Maxi22D1SF Then X22D1 = Int(N22D1 / Maxi22D1SF) + 1 Else X22D1 = N22D1 / Maxi22D1SF
     
                                                                                    'tps libre du dernier camion de la flotte
                                                                                    TapresT22D1 = ((X22D1 * Maxi22D1SF) - N22D1) * T22D1
     
                                                                                    'On regarde si le camion ne va pas etre sous utilisé sinon on passe au cas suivant
                                                                                    If T22D1 <= TapresT22D1 And TapresT22D1 < T42D1R1 Then GoTo suite
     
                                                                                    'le dernier camion de SF déblais ne peut être utiliser en DF avec R1 ou en DF avec R2 si N421R1=0 (s'il n'y a pas de tour en DF avec R1)
     
                                                                                    'on détermine le nb de camions qu'il faut pour le double fret
                                                                                    'on détermine le nb de tours en DF  du dernier camion de SF déblais
     
                                                                                    If N421R1 <> 0 Then
                                                                                    TSFDF2D1 = Int(TapresT22D1 / T42D1R1)
                                                                                        If Int((N421R1 - TSFDF2D1) / Maxi421) < ((N421R1 - TSFDF2D1) / Maxi421) Then X421R1 = Int((N421R1 - TSFDF2D1) / Maxi421) + 1 Else X421R1 = Int((N421R1 - TSFDF2D1) / Maxi421)
                                                                                        TapresT421 = ((X421R1 * Maxi421) - (N421R1 - TSFDF2D1)) * T42D1R1 'on détermine le tps restant du dernier camion
                                                                                        If T42D1R1 <= TapresT421 And TapresT421 < T32R1 Then GoTo suite
                                                                                        TDFSF2R1 = Int(TapresT421 / T32R1) 'on cherche le nb de tours que le dernier camion peut faire en SF R1
                                                                                        If Int((N32R1 - TDFSF2R1) / Maxi32R1SF) < ((N32R1 - TDFSF2R1) / Maxi32R1SF) Then X32R1 = Int((N32R1 - TDFSF2R1) / Maxi32R1SF) + 1 Else X32R1 = Int((N32R1 - TDFSF2R1) / Maxi32R1SF)
                                                                                        TapresT32R1 = ((X32R1 * Maxi32R1SF) - (N32R1 - TDFSF2R1)) * T32R1
                                                                                        If T32R1 < TapresT32R1 Then GoTo suite
     
                                                                                        If Int(N422R2 / Maxi422) < (N422R2 / Maxi422) Then X422R2 = Int(N422R2 / Maxi422) + 1 Else X422R2 = Int(N422R2 / Maxi422) 'on calcule le nb de camions en DF
                                                                                        TapresT422 = ((X422R2 * Maxi422) - N422R2) * T42D1R2
                                                                                        If T42D1R2 < TapresT422 And TapresT422 < T32R2 Then GoTo suite
                                                                                        TDFSF2R2 = Int(TapresT422 / T32R2)
                                                                                        If Int((N32R2 - TDFSF2R2) / Maxi32R2SF) < ((N32R2 - TDFSF2R2) / Maxi32R2SF) Then X32R2 = Int((N32R2 - TDFSF2R2) / Maxi32R2SF) + 1 Else X32R2 = Int((N32R2 - TDFSF2R2) / Maxi32R2SF) 'on détermine le nb de camions en SF r2
                                                                                        TapresT32R2 = ((X32R2 * Maxi32R2SF) - (N32R2 - TDFSF2R2)) * T32R2
                                                                                        If T32R2 < TapresT32R2 Then GoTo suite
     
     
                                                                                    Else 'si N421R1=0 alors le temps restant du SF déblais par sur le DF R2
                                                                                    TSFDF2D1 = Int(TapresT22D1 / T42D1R2)
                                                                                        If Int((N422R2 - TSFDF2D1) / Maxi422) < ((N422R2 - TSFDF2D1) / Maxi422) Then X422R2 = Int((N422R2 - TSFDF2D1) / Maxi422) + 1 Else X422R2 = Int((N422R2 - TSFDF2D1) / Maxi422)
                                                                                        TapresT422 = ((X422R2 * Maxi422) - (N422R2 - TSFDF2D1)) * T42D1R2 'on détermine le tps restant du dernier camion
                                                                                        If T42D1R2 <= TapresT422 And TapresT422 < T32R2 Then GoTo suite
                                                                                        TDFSF2R2 = Int(TapresT422 / T32R2)
                                                                                        If Int((N32R2 - TDFSF2R2) / Maxi32R2SF) < ((N32R2 - TDFSF2R2) / Maxi32R2SF) Then X32R2 = Int((N32R2 - TDFSF2R2) / Maxi32R2SF) + 1 Else X32R2 = Int((N32R2 - TDFSF2R2) / Maxi32R2SF) 'on détermine le nb de camions en SF r2
                                                                                        TapresT32R2 = ((X32R2 * Maxi32R2SF) - (N32R2 - TDFSF2R2)) * T32R2
                                                                                        If T32R2 < TapresT32R2 Then GoTo suite
     
                                                                                        If Int(N32R1 / Maxi32R1SF) < (N32R1 / Maxi32R1SF) Then X32R1 = Int(N32R1 / Maxi32R1SF) + 1 Else X32R1 = Int(N32R1 / Maxi32R1SF)
                                                                                        TapresT32R1 = ((X32R1 * Maxi32R1SF) - N32R1) * T32R1
                                                                                        If T32R1 < TapresT32R1 Then GoTo suite
     
                                                                                    End If
                                                                                End If
     
                                                                                'b) si N32D1=N431R1=N432R2=N33R1=N33R2=0, on va à la ligne suivante
                                                                                If Not (N23D1 = 0 And N431R1 = 0 And N432R2 = 0 And N33R1 = 0 And N33R2 = 0) Then
     
     
                                                                                    'on détermine le nombre de camions qu'il faut pour le double fret D1/R1
                                                                                    'on cherche X421R1 tq Maxi*(X421R1-1)<=s421R1<=Maxi*X421R1
                                                                                    If Int(N23D1 / Maxi23D1SF) < N23D1 / Maxi23D1SF Then X23D1 = Int(N23D1 / Maxi23D1SF) + 1 Else X23D1 = N23D1 / Maxi23D1SF
     
                                                                                    'tps libre du dernier camion de la flotte
                                                                                    TapresT23D1 = ((X23D1 * Maxi23D1SF) - N23D1) * T23D1
     
                                                                                    'On regarde si le camion ne va pas etre sous utilisé sinon on passe au cas suivant
                                                                                    If T23D1 <= TapresT23D1 And TapresT23D1 < T43D1R1 Then GoTo suite
     
                                                                                    'le dernier camion de SF déblais ne peut être utiliser en DF avec R1 ou en DF avec R2 si N421R1=0 (s'il n'y a pas de tour en DF avec R1)
     
                                                                                    'on détermine le nb de camions qu'il faut pour le double fret
                                                                                    'on détermine le nb de tours en DF  du dernier camion de SF déblais
     
                                                                                    If N431R1 <> 0 Then
                                                                                    TSFDF3D1 = Int(TapresT23D1 / T43D1R1)
                                                                                        If Int((N431R1 - TSFDF3D1) / Maxi431) < ((N431R1 - TSFDF3D1) / Maxi431) Then X431R1 = Int((N431R1 - TSFDF3D1) / Maxi431) + 1 Else X431R1 = Int((N431R1 - TSFDF3D1) / Maxi431)
                                                                                        TapresT431 = ((X431R1 * Maxi431) - (N431R1 - TSFDF3D1)) * T43D1R1 'on détermine le tps restant du dernier camion
                                                                                        If T43D1R1 <= TapresT431 And TapresT431 < T33R1 Then GoTo suite
                                                                                        TDFSF3R1 = Int(TapresT431 / T33R1) 'on cherche le nb de tours que le dernier camion peut faire en SF R1
                                                                                        If Int((N33R1 - TDFSF3R1) / Maxi33R1SF) < ((N33R1 - TDFSF3R1) / Maxi33R1SF) Then X33R1 = Int((N33R1 - TDFSF3R1) / Maxi33R1SF) + 1 Else X33R1 = Int((N33R1 - TDFSF3R1) / Maxi33R1SF)
                                                                                        TapresT33R1 = ((X33R1 * Maxi33R1SF) - (N33R1 - TDFSF3R1)) * T33R1
                                                                                        If T33R1 < TapresT33R1 Then GoTo suite
     
                                                                                        If Int(N432R2 / Maxi432) < (N432R2 / Maxi432) Then X432R2 = Int(N432R2 / Maxi432) + 1 Else X432R2 = Int(N432R2 / Maxi432) 'on calcule le nb de camions en DF
                                                                                        TapresT432 = ((X432R2 * Maxi432) - N432R2) * T43D1R2
                                                                                        If T43D1R2 < TapresT432 And TapresT432 < T33R2 Then GoTo suite
                                                                                        TDFSF3R2 = Int(TapresT432 / T33R2)
                                                                                        If Int((N33R2 - TDFSF3R2) / Maxi33R2SF) < ((N33R2 - TDFSF3R2) / Maxi33R2SF) Then X33R2 = Int((N33R2 - TDFSF3R2) / Maxi33R2SF) + 1 Else X33R2 = Int((N33R2 - TDFSF3R2) / Maxi33R2SF) 'on détermine le nb de camions en SF r2
                                                                                        TapresT33R2 = ((X33R2 * Maxi33R2SF) - (N33R2 - TDFSF3R2)) * T33R2
                                                                                        If T33R2 < TapresT33R2 Then GoTo suite
     
     
                                                                                    Else 'si N431R1=0 alors le temps restant du SF déblais par sur le DF R2
                                                                                    TSFDF3D1 = Int(TapresT23D1 / T43D1R2)
                                                                                        If Int((N432R2 - TSFDF3D1) / Maxi432) < ((N432R2 - TSFDF3D1) / Maxi432) Then X432R2 = Int((N432R2 - TSFDF3D1) / Maxi432) + 1 Else X432R2 = Int((N432R2 - TSFDF3D1) / Maxi432)
                                                                                        TapresT432 = ((X432R2 * Maxi432) - (N432R2 - TSFDF3D1)) * T43D1R2 'on détermine le tps restant du dernier camion
                                                                                        If T43D1R2 <= TapresT432 And TapresT432 < T33R2 Then GoTo suite
                                                                                        TDFSF3R2 = Int(TapresT432 / T33R2)
                                                                                        If Int((N33R2 - TDFSF3R2) / Maxi33R2SF) < ((N33R2 - TDFSF3R2) / Maxi33R2SF) Then X33R2 = Int((N33R2 - TDFSF3R2) / Maxi33R2SF) + 1 Else X33R2 = Int((N33R2 - TDFSF3R2) / Maxi33R2SF) 'on détermine le nb de camions en SF r2
                                                                                        TapresT33R2 = ((X33R2 * Maxi33R2SF) - (N33R2 - TDFSF3R2)) * T33R2
                                                                                        If T33R2 < TapresT33R2 Then GoTo suite
     
                                                                                        If Int(N33R1 / Maxi33R1SF) < (N33R1 / Maxi33R1SF) Then X33R1 = Int(N33R1 / Maxi33R1SF) + 1 Else X33R1 = Int(N33R1 / Maxi33R1SF)
                                                                                        TapresT33R1 = ((X33R1 * Maxi33R1SF) - N33R1) * T33R1
                                                                                        If T33R1 < TapresT33R1 Then GoTo suite
     
                                                                                    End If
                                                                                End If
     
     
     
     
                                                                                    Xtot2 = X22D1 + X32R1 + X32R2 + X421R1 + X422R2
                                                                                    Xtot3 = X23D1 + X33R1 + X33R2 + X431R1 + X432R2
     
                                                                                    'on regroupe ttes les infos concernant la ligne, les N, les A et B, Xtot2 et Xtot3
                                                                                    StrAntiDoublon = CStr(N22D1) & "-" & CStr(N32R1) & "-" & CStr(N32R2) & "-" & CStr(N421R1) & "-" & CStr(N422R2) & "-" & CStr(N42D1) & "-" & CStr(N23D1) & "-" & CStr(N33R1) & "-" & CStr(N33R2) & "-" & CStr(N431R1) & "-" & CStr(N432R2) & "-" & CStr(N43D1) & "-" & CStr(A) & "-" & CStr(B1) & "-" & CStr(B2) & "-" & CStr(Xtot2) & "-" & CStr(Xtot3)
     
                                                                                    'on regarde si ces infos existent déjà
                                                                                    If DicoAntiDoublon.exists(StrAntiDoublon) Then GoTo suite
     
                                                                                    'on les rajoute puisqu'elles ne figurent pas dans le dico
                                                                                    DicoAntiDoublon.Add StrAntiDoublon, 0
     
     
     
     
     
     
                                                                                    'Si le code arrive ici c'est que notre flotte est bien occupé, donc on note les résultats dans le tableau
     
                                                                                    Cells(Ligne, "A").Value = z22D1 * w22D1
                                                                                    Cells(Ligne, "B").Value = z421R1 * w421R1
                                                                                    Cells(Ligne, "C").Value = z422R2 * w422R2
                                                                                    Cells(Ligne, "D").Value = Cells(Ligne, "B").Value + Cells(Ligne, "C").Value
                                                                                    Cells(Ligne, "E").Value = z32R1 * w32R1
                                                                                    Cells(Ligne, "F").Value = z32R2 * w32R2
                                                                                    Cells(Ligne, "G").Value = z23D1 * w23D1
                                                                                    Cells(Ligne, "H").Value = z431R1 * w431R1
                                                                                    Cells(Ligne, "I").Value = z432R2 * w432R2
                                                                                    Cells(Ligne, "J").Value = Cells(Ligne, "H").Value + Cells(Ligne, "I").Value
                                                                                    Cells(Ligne, "K").Value = z33R1 * w33R1
                                                                                    Cells(Ligne, "L").Value = z33R2 * w33R2
                                                                                    Cells(Ligne, "M").Value = A
                                                                                    Cells(Ligne, "N").Value = B1
                                                                                    Cells(Ligne, "O").Value = B2
     
     
     
     
                                                                                    Cells(Ligne, "Q") = N22D1 * T22D1
                                                                                    Cells(Ligne, "R") = N421R1 * T42D1R1
                                                                                    Cells(Ligne, "S") = N422R2 * T42D1R2
                                                                                    Cells(Ligne, "T") = N32R1 * T32R1
                                                                                    Cells(Ligne, "U") = N32R2 * T32R2
                                                                                    Cells(Ligne, "AI") = N23D1 * T23D1
                                                                                    Cells(Ligne, "AJ") = N431R1 * T43D1R1
                                                                                    Cells(Ligne, "AK") = N432R2 * T43D1R2
                                                                                    Cells(Ligne, "AL") = N33R1 * T33R1
                                                                                    Cells(Ligne, "AM") = N33R2 * T33R2
     
     
                                                                                    'Xtot2 = X22 + X42 + X32
                                                                                    Cells(Ligne, "V") = X22D1
                                                                                    Cells(Ligne, "W") = TapresT22D1
                                                                                    Cells(Ligne, "X") = X421R1
                                                                                    Cells(Ligne, "Y") = TapresT421
                                                                                    Cells(Ligne, "Z") = X422R2
                                                                                    Cells(Ligne, "AA") = TapresT422
                                                                                    Cells(Ligne, "AB") = X32R1
                                                                                    Cells(Ligne, "AC") = TapresT32R1
                                                                                    Cells(Ligne, "AD") = X32R2
                                                                                    Cells(Ligne, "AE") = TapresT32R2
                                                                                    Cells(Ligne, "AF") = X421R1 + X422R2
                                                                                    Cells(Ligne, "AG") = X22D1 + X421R1 + X422R2 + X32R1 + X32R2 'Xtot2
     
     
                                                                                    'Xtot3 = X23 + X43 + X33
                                                                                    Cells(Ligne, "AN") = X23D1
                                                                                    Cells(Ligne, "AO") = TapresT23D1
                                                                                    Cells(Ligne, "AP") = X431R1
                                                                                    Cells(Ligne, "AQ") = TapresT431
                                                                                    Cells(Ligne, "AR") = X432R2
                                                                                    Cells(Ligne, "AS") = TapresT432
                                                                                    Cells(Ligne, "AT") = X33R1
                                                                                    Cells(Ligne, "AU") = TapresT23D1
                                                                                    Cells(Ligne, "AV") = X33R2
                                                                                    Cells(Ligne, "AW") = TapresT33R2
                                                                                    Cells(Ligne, "AX") = X431R1 + X432R2
                                                                                    Cells(Ligne, "AY") = X23D1 + X431R1 + X432R2 + X33R1 + X33R2 'Xtot3
     
                                                                                    Cells(Ligne, "BA") = (X22D1 + X421R1 + X422R2 + X32R1 + X32R2) * 480 + (X23D1 + X431R1 + X432R2 + X33R1 + X33R2) * 550
                                                                                    Ligne = Ligne + 1
     
                                                                                    End If
                                                                                    End If
    suite:
     
                                                                                    Next
                                                                                Next
                                                                            Next
                                                                        Next
                                                                    Next
                                                                Next
                                                            Next
                                                        Next
                                                    Next
                                                Next
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
     
     
    DicoAntiDoublon.RemoveAll
    Set DicoAntiDoublon = Nothing
    Application.ScreenUpdating = True
     
    End Sub
    est-ce que ce problème vient du code?
    Ou est-ce qu'EXCEL est pas assez puissant?

  20. #60
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 128
    Par défaut
    est-ce que ce problème vient du code?
    Ou est-ce qu'EXCEL est pas assez puissant?
    Un peu d'humilité

    Alors voila ce que je te propose, le code devrait être suffisamment polyvalent pour accepter des types de camion/remblai/deblai divers et variés.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    Option Explicit
    Option Base 1
    Sub Essai()
    Dim Tab_TpTrajet, Tab_TpTrxMax, Tab_Trajet, Tab_Volum
    Dim Tab_Resultat() As Integer, Tab_TrajetMax() As Integer
    Dim NbrColResultat As Integer
    'Ne pas oublier d'activer Microsoft scripting runtime dans les references (Menu outil)
    Dim DicoDeblai As New Dictionary, DicoRemblai As New Dictionary
    Dim LecD As Integer, LecR As Integer, mLec As Integer
    Dim iTmp As Integer, iTmpD As Integer, iLec As Integer
    Dim Occupation As Single
    'Dim TpTrajetMin As Single
    'Dim TpTrxMax As Single
    'Dim NbrTrajetMax As Integer
    Dim iRow As Integer, iCol As Integer, iType As Integer, iResult As Integer
    Dim iColD As Integer, iColR As Integer
    Dim iTmpVal As Integer
    Dim NbrType As Integer
    Dim NbrTrajet As Integer
     
    'On recup les données, on fera mieux par la suite, pour le moment on va chercher dans le tableau a des endroits fixent
    Tab_TpTrxMax = Feuil1.Range("B2:D2")
    Tab_Volum = Feuil1.Range("B3:D3")
    Tab_Trajet = Feuil1.Range("A8:A12")
    Tab_TpTrajet = Feuil1.Range("B8:D12")
    NbrType = 3
    NbrTrajet = UBound(Tab_Trajet, 1)
     
    'On cherche le plus petit temps de trajet
    'TpTrajetMin = Application.WorksheetFunction.Min(Tab_TpTrajet)
     
    'On cherche le type de camion ayant la plus grosse amplitude horraire
    'TpTrxMax = Application.WorksheetFunction.Max(Tab_TpTrajet)
     
    'On calcule le plus grand nombre de trajets pouvant etre effectués
    'NbrTrajetMax = Int(TpTrxMax / TpTrajetMin)
     
    'On va maintenant rechercher le nombre de remblai/deblai
    For iCol = 1 To NbrTrajet
        If LectureFret(Tab_Trajet(iCol, 1), LecD, LecR) Then
            'On renseigne les dicos
            If (Not DicoDeblai.Exists(LecD)) And (LecD <> 0) Then
                DicoDeblai.Add LecD, 0
            End If
            If (Not DicoRemblai.Exists(LecR)) And (LecR <> 0) Then
                DicoRemblai.Add LecR, 0
            End If
            If mLec < LecR Then mLec = LecR
            If mLec < LecD Then mLec = LecD
        Else
            'il faut gerer l'erreur
        End If
    Next
     
    'On modifie les valeur des items pour reperer les entrée des dico par ordre croissant en fct° du contenu de Key
    Dim Tab_Q() As String
    ReDim Tab_Q(DicoDeblai.Count + DicoRemblai.Count)
    iTmp = 1
    For iLec = 0 To mLec
        If DicoDeblai.Exists(iLec) Then
            DicoDeblai.Item(iLec) = iTmp
            Tab_Q(iTmp) = "QD" & iLec
            iTmp = iTmp + 1
        End If
    Next
    iTmp = 1
    For iLec = 0 To mLec
        If DicoRemblai.Exists(iLec) Then
            DicoRemblai.Item(iLec) = iTmp
            Tab_Q(iTmp + DicoDeblai.Count) = "QR" & iLec
            iTmp = iTmp + 1
        End If
    Next
     
    'On crée le tableau qui contiendra les résultats
    NbrColResultat = NbrTrajet + DicoDeblai.Count + DicoRemblai.Count
    ReDim Tab_Resultat(NbrType, NbrColResultat, 1)
    iResult = 1
     
    'on calcule le nombre de trajets max
    ReDim Tab_TrajetMax(NbrTrajet)
     
    For iType = 1 To NbrType
     
        'On calcule le nombre de trajets max pour ce type en fct° des trajet
        For iCol = 1 To NbrTrajet
            If CInt(Tab_TpTrajet(iCol, iType)) = 0 Then
                Tab_TrajetMax(iCol) = 0
            Else
                Tab_TrajetMax(iCol) = Int(Tab_TpTrxMax(1, iType) / Tab_TpTrajet(iCol, iType))
            End If
            'On initialise notre tableau de resultat avec cette valeur max
            Tab_Resultat(iType, iCol, 1) = Tab_TrajetMax(iCol)
        Next
        'on cherche toutes les combinaisons possibles
        Do
            'On controle l'occupation du camion
            Occupation = 0
            For iCol = 1 To NbrTrajet
                Occupation = Occupation + Tab_Resultat(iType, iCol, iResult) * Tab_TpTrajet(iCol, iType)
            Next
     
            If (Tab_TpTrxMax(1, iType) >= Occupation) And (Occupation > Tab_TpTrxMax(1, iType) - 1) Then
                'Timing ok
                'On calcule les Q de deblai et de Remblai
                For iCol = 1 To NbrTrajet
                    If LectureFret(Tab_Trajet(iCol, 1), LecD, LecR) Then
                        'On ajoute le deblai transporté par ce camion au total de ce type de deblai
                        If LecD <> 0 Then
                            iColD = NbrTrajet + DicoDeblai.Item(LecD)
                            Tab_Resultat(iType, iColD, iResult) = Tab_Resultat(iType, iColD, iResult) + Tab_Resultat(iType, iCol, iResult) * Tab_Volum(1, iType)
                        End If
                        'Idem pour le remblai
                        If LecR <> 0 Then
                            iColR = NbrTrajet + DicoDeblai.Count + DicoRemblai.Item(LecR)
                            Tab_Resultat(iType, iColR, iResult) = Tab_Resultat(iType, iColR, iResult) + Tab_Resultat(iType, iCol, iResult) * Tab_Volum(1, iType)
                        End If
                    Else
                        'gerer erreur
                    End If
                Next
                'on garde ce resultat
                iResult = iResult + 1
                'On agrandi le tableau si besoin
                If iResult > UBound(Tab_Resultat, 3) Then ReDim Preserve Tab_Resultat(NbrType, UBound(Tab_Resultat, 2), iResult)
                'On stop la decrementation de la derniere colonne, on lui donne comme valeur -1 pour etre traité plus loin
                Tab_Resultat(iType, NbrTrajet, iResult) = -1
                'On reporte les valeurs dans la ligne suivante
                For iCol = 1 To NbrTrajet - 1
                    Tab_Resultat(iType, iCol, iResult) = Tab_Resultat(iType, iCol, iResult - 1)
                Next
            Else
                'On decremente le dernier trajet
                Tab_Resultat(iType, NbrTrajet, iResult) = Tab_Resultat(iType, NbrTrajet, iResult) - 1
            End If
     
            'Controle de la cascade
            For iCol = NbrTrajet To 1 Step -1
                iTmpVal = Tab_Resultat(iType, iCol, iResult)
                If iTmpVal = -1 And iCol = 1 Then
                    'On est arrivé a la fin des possibilités
                    'On vide le contenu de la ligne
                    For iRow = 1 To NbrTrajet
                        Tab_Resultat(iType, iRow, iResult) = 0
                    Next
                    Exit Do
                ElseIf iTmpVal = -1 Then
                    'On remet cette case a sont nombre maxi
                    iTmpVal = Tab_TrajetMax(iCol)
                    'on decremente la case precedente de 1
                    Tab_Resultat(iType, iCol - 1, iResult) = Tab_Resultat(iType, iCol - 1, iResult) - 1
                End If
                'On met la nouvelle valeur modifié
                Tab_Resultat(iType, iCol, iResult) = iTmpVal
            Next
        Loop Until False
        iResult = 1
    Next
     
    'Routine permetant l'affiche pour voir les resulatats
    Dim Tab_Aff() As String
     
    ReDim Tab_Aff(UBound(Tab_Resultat, 2), UBound(Tab_Resultat, 3) + 2)
     
    'On met les entete de colonne dans le tableau qui va etre affiché dans la feuil2
    For iCol = 1 To NbrTrajet
        Tab_Aff(iCol, 2) = Tab_Trajet(iCol, 1)
    Next
    For iCol = 1 To DicoDeblai.Count
        Tab_Aff(iCol + NbrTrajet, 2) = Tab_Q(iCol)
    Next
    For iCol = 1 To DicoRemblai.Count
        Tab_Aff(iCol + NbrTrajet + DicoDeblai.Count, 2) = Tab_Q(iCol + DicoDeblai.Count)
    Next
     
     
    For iType = 1 To UBound(Tab_Resultat, 1)
        'On note le type du camion
        Tab_Aff(1, 1) = "Camion " & Tab_Volum(1, iType) & "m3"
        For iCol = 1 To UBound(Tab_Resultat, 2)
            For iRow = 1 To UBound(Tab_Resultat, 3)
                Tab_Aff(iCol, iRow + 2) = Tab_Resultat(iType, iCol, iRow)
            Next
        Next
        Feuil2.Cells(1 + (iType - 1) * UBound(Tab_Resultat, 3) + (iType - 1) * 3, "A").Resize(iRow - 1, iCol - 1).Value = WorksheetFunction.Transpose(Tab_Aff)
    Next
     
    DicoDeblai.RemoveAll
    DicoRemblai.RemoveAll
    Set DicoRemblai = Nothing
    Set DicoDeblai = Nothing
     
    End Sub
     
     
    Function LectureFret(ByVal Nom As String, ByRef aLecD As Integer, ByRef aLecR As Integer) As Boolean
    Dim NomPur As String
    Dim PosTiret As Integer
     
    'On controle que nom ne soit pas vide... il faudrait faire plus de controle peut etre, on vera ca si les resultats sont probants ;)
    If Nom = "" Then
        LectureFret = False
        Exit Function
    End If
     
    'On va supprimer la partie qui ne sert a rien (SF ou DF)
    NomPur = Right(Nom, Len(Nom) - 2) 'On supprime les 2 1er caracteres
     
    'On cherche la position du tiret dans le texte
    PosTiret = InStr(1, NomPur, "-")
    If PosTiret = 0 Then
        'Uniquement du simple fret
        aLecD = CInt(NomPur)
        aLecR = 0
    Else
        aLecD = Mid(NomPur, 1, PosTiret - 1)
        aLecR = Mid(NomPur, PosTiret + 1, Len(NomPur) - PosTiret)
    End If
     
    LectureFret = True
     
    End Function
    Je te joint le fichier, le résultat est affiché en feuil2, bien sur pour l'instant seules toutes les combinaisons possibles par type de camions sont faites.
    Il va maintenant falloir utiliser ces résultats pour calculer les rendements en fonction des camions de la flotte afin de déterminer si une solution existe au vu des rendement que tu auras demandé.

    ++
    Qwaz

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

Discussions similaires

  1. Réponses: 0
    Dernier message: 25/03/2013, 14h39
  2. Faire un tableau a nombre de colonnes variables
    Par mcfly37 dans le forum Tapestry
    Réponses: 8
    Dernier message: 17/09/2010, 14h21
  3. [RegEx] Analyse de tableau HTML avec nombre variable de cases
    Par ddelec24 dans le forum Langage
    Réponses: 9
    Dernier message: 11/04/2009, 21h39
  4. Réponses: 8
    Dernier message: 14/11/2007, 10h27
  5. Réponses: 1
    Dernier message: 05/01/2007, 15h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo