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 :

Boucle dans une boucle ? [XL-2010]


Sujet :

Macros et VBA Excel

  1. #1
    Membre du Club
    Homme Profil pro
    Derrière l'écran
    Inscrit en
    Novembre 2012
    Messages
    161
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Derrière l'écran

    Informations forums :
    Inscription : Novembre 2012
    Messages : 161
    Points : 68
    Points
    68
    Par défaut Boucle dans une boucle ?
    Bonjour à tous

    J'ai sur une feuille A4, 4 fois le même tableau (en carré)
    Les 4 tableaux renvois vers les mêmes formules de calcul pour des personnes différentes.

    Ci joint ma 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
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Variables des différents tableaux
    Dim t1eh As Integer
    Dim t2eh As Integer
    Dim t3eh As Integer
    Dim t4eh As Integer
    Dim t1eq As Integer
    Dim t2eq As Integer
    Dim t3eq As Integer
    Dim t4eq As Integer
     
    'Automatisation cellule 1er tableau (haut à gauche) éléments en heures
    For t1eh = 7 To 12
    If Target.Address = "$G$ & t1eh" Then
    Else
    If Range("G" & t1eh) = "" Then
    Cells(t1eh, 9) = ""
    Else
    End If
    If Range("G" & t1eh) = "Intervention astreinte jour" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eh) = "Majoration férié travaillé" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eh) = "Majoration de dimanche" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eh) = "Majoration de nuit" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eh) = "Intervention astreinte nuit" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eh) = "Heures à 100%" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eh) = "Heures à 110%" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eh) = "Heures à 125%" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eh) = "Heures à 150%" Then
    Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    End If
    Next
    'Automatisation cellule 1er tableau (haut à gauche) éléments en quantité
    For t1eq = 15 To 21
    If Target.Address = "$G$ & t1eq" Then
    Else
    If Range("G" & t1eq) = "" Then
    Cells(t1eq, 9) = ""
    Else
    End If
    If Range("G" & t1eq) = "Panier jour taxable" Then
    Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eq) = "Indemnité astreinte dimanche" Then
    Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eq) = "Indemnité astreinte semaine" Then
    Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eq) = "Panier jour non taxable" Then
    Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eq) = "Panier nuit non taxable" Then
    Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eq) = "Panier nuit taxable" Then
    Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eq) = "IPCM non taxable" Then
    Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    If Range("G" & t1eq) = "IPCM taxable" Then
    Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
    Else
    End If
    End If
    Next
     
     
    'Automatisation cellule 2ème tableau (haut à droite) éléments en heures
    For t2eh = 7 To 12
    If Target.Address = "$R$ & t2eh" Then
    Else
    If Range("R" & t2eh) = "" Then
    Cells(t2eh, 20) = ""
    Else
    End If
    If Range("R" & t2eh) = "Intervention astreinte jour" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eh) = "Majoration férié travaillé" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eh) = "Majoration de dimanche" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eh) = "Majoration de nuit" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eh) = "Intervention astreinte nuit" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eh) = "Heures à 100%" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eh) = "Heures à 110%" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eh) = "Heures à 125%" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eh) = "Heures à 150%" Then
    Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    End If
    Next
    'Automatisation cellule 2ème tableau (haut à droite) éléments en quantité
    For t2eq = 15 To 21
    If Target.Address = "$R$ & t2eq" Then
    Else
    If Range("R" & t2eq) = "" Then
    Cells(t2eq, 20) = ""
    Else
    End If
    If Range("R" & t2eq) = "Panier jour taxable" Then
    Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eq) = "Indemnité astreinte dimanche" Then
    Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eq) = "Indemnité astreinte semaine" Then
    Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eq) = "Panier jour non taxable" Then
    Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eq) = "Panier nuit non taxable" Then
    Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eq) = "Panier nuit taxable" Then
    Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eq) = "IPCM non taxable" Then
    Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    If Range("R" & t2eq) = "IPCM taxable" Then
    Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
    Else
    End If
    End If
    Next
     
     
    'Automatisation cellule 3ème tableau (bas à gauche) éléments en heures
    For t3eh = 29 To 34
    If Target.Address = "$G$ & t3eh" Then
    Else
    If Range("G" & t3eh) = "" Then
    Cells(t3eh, 9) = ""
    Else
    End If
    If Range("G" & t3eh) = "Intervention astreinte jour" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eh) = "Majoration férié travaillé" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eh) = "Majoration de dimanche" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eh) = "Majoration de nuit" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eh) = "Intervention astreinte nuit" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eh) = "Heures à 100%" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eh) = "Heures à 110%" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eh) = "Heures à 125%" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eh) = "Heures à 150%" Then
    Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    End If
    Next
    'Automatisation cellule 3ème tableau (bas à gauche) éléments en quantité
    For t3eq = 37 To 43
    If Target.Address = "$G$ & t3eq" Then
    Else
    If Range("G" & t3eq) = "" Then
    Cells(t3eq, 9) = ""
    Else
    End If
    If Range("G" & t3eq) = "Panier jour taxable" Then
    Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eq) = "Indemnité astreinte dimanche" Then
    Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eq) = "Indemnité astreinte semaine" Then
    Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eq) = "Panier jour non taxable" Then
    Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eq) = "Panier nuit non taxable" Then
    Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eq) = "Panier nuit taxable" Then
    Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eq) = "IPCM non taxable" Then
    Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    If Range("G" & t3eq) = "IPCM taxable" Then
    Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
    Else
    End If
    End If
    Next
     
     
    'Automatisation cellule 4ème tableau (bas à droite) éléments en heures
    For t4eh = 29 To 34
    If Target.Address = "$R$ & t4eh" Then
    Else
    If Range("R" & t4eh) = "" Then
    Cells(t4eh, 20) = ""
    Else
    End If
    If Range("R" & t4eh) = "Intervention astreinte jour" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eh) = "Majoration férié travaillé" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eh) = "Majoration de dimanche" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eh) = "Majoration de nuit" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eh) = "Intervention astreinte nuit" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eh) = "Heures à 100%" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eh) = "Heures à 110%" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eh) = "Heures à 125%" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eh) = "Heures à 150%" Then
    Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    End If
    Next
    'Automatisation cellule 3ème tableau (bas à gauche) éléments en quantité
    For t4eq = 37 To 43
    If Target.Address = "$G$ & t4eq" Then
    Else
    If Range("R" & t4eq) = "" Then
    Cells(t4eq, 20) = ""
    Else
    End If
    If Range("R" & t4eq) = "Panier jour taxable" Then
    Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eq) = "Indemnité astreinte dimanche" Then
    Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eq) = "Indemnité astreinte semaine" Then
    Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eq) = "Panier jour non taxable" Then
    Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eq) = "Panier nuit non taxable" Then
    Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eq) = "Panier nuit taxable" Then
    Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eq) = "IPCM non taxable" Then
    Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    If Range("R" & t4eq) = "IPCM taxable" Then
    Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
    Else
    End If
    End If
    Next
    End Sub
    Dans ma ligne de codes, j'ai donc 4 fois la même chose sauf que les cellules changent en fonction de l'un de ses 4 tableaux.
    tableau 1 codes de la ligne 12 à 99
    tableau 2 codes de la ligne 102 à 189
    tableau 3 codes de la ligne 192 à 279
    tableau 4 codes de la ligne 282 à 369

    Avec une boucle comment je pourrais faire pour avoir que lignes 12 à 99 mais que cela se reproduise sur les 3 autres tableaux automatiquement avec des variables au départ bien placé et bien défini dans la macro.

  2. #2
    Membre averti
    Homme Profil pro
    Ingénieur Industrialisation
    Inscrit en
    Mai 2015
    Messages
    222
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur Industrialisation
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2015
    Messages : 222
    Points : 412
    Points
    412
    Par défaut
    Salut à toi,

    Passe par une fonction ou sous procédure ! Je me permets juste au passage de proposer un moyen de simplification de ta macro qui est très lourde... Beaucoup de "Else" inutiles et surtout ton code passe par toutes les conditions alors qu'il devrait à chaque fois s'arrêter une fois qu'il a rencontré son cas...

    D'ailleurs, le mot cas est très pratique ici, utilise le Select Case !

    Ah, au passage, ceci ne fonctionnera pas If Target.Address = "$R$ & t2eq" Then, les guillemets ne sont pas au bon endroit !! Il faudrait If Target.Address = "$R$" & t2eq Then

    NOTA : je me suis engagé dans un chantier vraiment trop gros pour être rapidement traité et je n'en aurai pas le temps. Par contre je te conseille de faire quelque chose du genre :

    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
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Variables des différents tableaux
    Dim t1eh As Integer
    Dim t2eh As Integer
    Dim t3eh As Integer
    Dim t4eh As Integer
    Dim t1eq As Integer
    Dim t2eq As Integer
    Dim t3eq As Integer
    Dim t4eq As Integer
     
    'Automatisation cellule 1er tableau (haut à gauche) éléments en heures
    Call TaSub1(7, 12)
    Call TaSub2(15, 21)
    Call TaSub3(7, 12)
    'etc
     
    End Sub
     
    Sub TaSub1(Début As Double, Fin As Double)
    For ligne = Début To Fin
        If Not Target.Address = "$G$" & ligne Then
            With Cells(ligne, 9)
                Select Case Range("G" & ligne).Text
                    Case ""
                        .Value = ""
     
                    Case "Intervention astreinte jour"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                    Case "Majoration férié travaillé"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                    Case "Majoration de dimanche"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                    Case "Majoration de nuit"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                    Case "Intervention astreinte nuit"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                    Case "Heures à 100%"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                    Case "Heures à 110%"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                    Case "Heures à 125%"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                    Case "Heures à 150%"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
     
                End Select
            End With
        End If
    Next ligne
    End Sub
     
     
    Sub TaSub2()
    '    Ici faire pareil 
    End Sub
    Rappel : ce n'est pas du tout complet et je ne réponds peut-être pas au problème !! La seule chose qui manque pour n'avoir que 2 sous procédures (si j'ai bien compris ton code) serait de mettre en 3ème paramètre la colonne qui varie dans les SOMME.SI.ENS. Si j'ai le temps ce soir, je regarderai mais là je ne peux malheureusement pas !

    Quentin

  3. #3
    Expert éminent

    Homme Profil pro
    Curieux
    Inscrit en
    Juillet 2012
    Messages
    5 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2012
    Messages : 5 073
    Points : 9 853
    Points
    9 853
    Billets dans le blog
    5
    Par défaut
    Bonjour,

    oulalala !

    rien qu'en optimisant l'écriture de tes if, on tombe à 100 lignes
    en déclarant des astucieux tableaux (6 ou 7), l'ensemble de ton code tiens dans une série de boucles imbriquées, soit environ 20 lignes de codes (hors déclarations)

    cependant, la solution est ailleurs ... pourquoi réécrire tes formules à chaque changement de sélection ?
    cette macro travaille à chaque changement de cellule, effectue quantité de tests pour (peut être) au final ne rien faire à la fin

    ça doit pas mal ramer sur cette feuille

    il faudrait un peu nous décrire ce qui se passe sur la feuille en terme de manipulations "utilisateurs"
    un fichier exemple serait, je pense, le bienvenu.

    et tu veux faire quoi ici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    If Target.Address = "$G$ & t1eh" Then
    Else
    tieh étant une variable, tu dois la sortir des guillements si tu veux tester sa valeur ... sinon ça sera toujours faux
    donc ce if/else/end if ne sert à rien du tout, tu vas toujours entrer dans ton else quoi qu'il arrive

    et au passage, toutes tes variable t1eh et compagnie ... une seule suffit !

    tiens, juste en utilisant correctement les if ... je n'ai pas du tout réduit tes variables et tes If inutiles

    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
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Variables des différents tableaux
    Dim t1eh As Integer
    Dim t2eh As Integer
    Dim t3eh As Integer
    Dim t4eh As Integer
    Dim t1eq As Integer
    Dim t2eq As Integer
    Dim t3eq As Integer
    Dim t4eq As Integer
     
    'Automatisation cellule 1er tableau (haut à gauche) éléments en heures
        For t1eh = 7 To 12
           If Target.Address <> "$G$ & t1eh" Then
            If Range("G" & t1eh) = "" Then Cells(t1eh, 9) = ""
            If Range("G" & t1eh) = "Intervention astreinte jour" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eh) = "Majoration férié travaillé" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eh) = "Majoration de dimanche" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eh) = "Majoration de nuit" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eh) = "Intervention astreinte nuit" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eh) = "Heures à 100%" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eh) = "Heures à 110%" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eh) = "Heures à 125%" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eh) = "Heures à 150%" Then Cells(t1eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
        Next
     
    'Automatisation cellule 2ème tableau (haut à droite) éléments en heures
    For t2eh = 7 To 12
        If Target.Address <> "$R$ & t2eh" Then
            If Range("R" & t2eh) = "" Then Cells(t2eh, 20) = ""
            If Range("R" & t2eh) = "Intervention astreinte jour" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eh) = "Majoration férié travaillé" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eh) = "Majoration de dimanche" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eh) = "Majoration de nuit" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eh) = "Intervention astreinte nuit" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eh) = "Heures à 100%" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eh) = "Heures à 110%" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eh) = "Heures à 125%" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eh) = "Heures à 150%" Then Cells(t2eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
        End If
    Next
     
    'Automatisation cellule 3ème tableau (bas à gauche) éléments en heures
    For t3eh = 29 To 34
        If Target.Address <> "$G$ & t3eh" Then
            If Range("G" & t3eh) = "" Then Cells(t3eh, 9) = ""
            If Range("G" & t3eh) = "Intervention astreinte jour" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eh) = "Majoration férié travaillé" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eh) = "Majoration de dimanche" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eh) = "Majoration de nuit" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eh) = "Intervention astreinte nuit" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eh) = "Heures à 100%" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eh) = "Heures à 110%" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eh) = "Heures à 125%" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eh) = "Heures à 150%" Then Cells(t3eh, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
        End If
    Next
     
    'Automatisation cellule 4ème tableau (bas à droite) éléments en heures
    For t4eh = 29 To 34
        If Target.Address <> "$R$ & t4eh" Then
            If Range("R" & t4eh) = "" Then Cells(t4eh, 20) = ""
            If Range("R" & t4eh) = "Intervention astreinte jour" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eh) = "Majoration férié travaillé" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eh) = "Majoration de dimanche" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eh) = "Majoration de nuit" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eh) = "Intervention astreinte nuit" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eh) = "Heures à 100%" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eh) = "Heures à 110%" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)+SOMME.SI.ENS(Variables!S:S;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eh) = "Heures à 125%" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)+SOMME.SI.ENS(Variables!T:T;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eh) = "Heures à 150%" Then Cells(t4eh, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
        End If
    Next
     
    'Automatisation cellule 1er tableau (haut à gauche) éléments en quantité
    For t1eq = 15 To 21
        If Target.Address <> "$G$ & t1eq" Then
            If Range("G" & t1eq) = "" Then Cells(t1eq, 9) = ""
            If Range("G" & t1eq) = "Panier jour taxable" Then Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eq) = "Indemnité astreinte dimanche" Then Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eq) = "Indemnité astreinte semaine" Then Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eq) = "Panier jour non taxable" Then Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eq) = "Panier nuit non taxable" Then Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eq) = "Panier nuit taxable" Then Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eq) = "IPCM non taxable" Then Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
            If Range("G" & t1eq) = "IPCM taxable" Then Cells(t1eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;C5;Variables!D:D;"">=""&C9;Variables!D:D;""<=""&C10)"
        End If
    Next
     
    'Automatisation cellule 2ème tableau (haut à droite) éléments en quantité
    For t2eq = 15 To 21
        If Target.Address <> "$R$ & t2eq" Then
            If Range("R" & t2eq) = "" Then Cells(t2eq, 20) = ""
            If Range("R" & t2eq) = "Panier jour taxable" Then Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eq) = "Indemnité astreinte dimanche" Then Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eq) = "Indemnité astreinte semaine" Then Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eq) = "Panier jour non taxable" Then Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eq) = "Panier nuit non taxable" Then Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eq) = "Panier nuit taxable" Then Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eq) = "IPCM non taxable" Then Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
            If Range("R" & t2eq) = "IPCM taxable" Then Cells(t2eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;N5;Variables!D:D;"">=""&N9;Variables!D:D;""<=""&N10)"
        End If
    Next
     
    'Automatisation cellule 3ème tableau (bas à gauche) éléments en quantité
    For t3eq = 37 To 43
        If Target.Address <> "$G$ & t3eq" Then
            If Range("G" & t3eq) = "" Then Cells(t3eq, 9) = ""
            If Range("G" & t3eq) = "Panier jour taxable" Then Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eq) = "Indemnité astreinte dimanche" Then Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eq) = "Indemnité astreinte semaine" Then Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eq) = "Panier jour non taxable" Then Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eq) = "Panier nuit non taxable" Then Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eq) = "Panier nuit taxable" Then Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eq) = "IPCM non taxable" Then Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
            If Range("G" & t3eq) = "IPCM taxable" Then Cells(t3eq, 9).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;C27;Variables!D:D;"">=""&C31;Variables!D:D;""<=""&C32)"
        End If
    Next
     
    'Automatisation cellule 3ème tableau (bas à gauche) éléments en quantité
    For t4eq = 37 To 43
        If Target.Address = "$G$ & t4eq" Then
            If Range("R" & t4eq) = "" Then Cells(t4eq, 20) = ""
            If Range("R" & t4eq) = "Panier jour taxable" Then Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eq) = "Indemnité astreinte dimanche" Then Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eq) = "Indemnité astreinte semaine" Then Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eq) = "Panier jour non taxable" Then Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eq) = "Panier nuit non taxable" Then Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eq) = "Panier nuit taxable" Then Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eq) = "IPCM non taxable" Then Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
            If Range("R" & t4eq) = "IPCM taxable" Then Cells(t4eq, 20).FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;N27;Variables!D:D;"">=""&N31;Variables!D:D;""<=""&N32)"
        End If
    Next
     
    End Sub

  4. #4
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    For i=0 to 96
    Range("a12").offset(i)'tableau 1 codes de la ligne 12 à 99
    Range("a102").offset(i)' tableau 2 codes de la ligne 102 à 189
    Range("a192").offset(i)' tableau 3 codes de la ligne 192 à 279
    Range("a382").offset(i) 'tableau 4 codes de la ligne 282 à 369
    Next
    voila pour tes 4 tableau c'est réglé.

    Maintenant tu peux , comme l'a dit Quentin, faire une fonction!

  5. #5
    Membre du Club
    Homme Profil pro
    Derrière l'écran
    Inscrit en
    Novembre 2012
    Messages
    161
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Derrière l'écran

    Informations forums :
    Inscription : Novembre 2012
    Messages : 161
    Points : 68
    Points
    68
    Par défaut
    Merci beaucoup de votre aide,
    mais je m'embrouille un peu avec tous ces conseils.

    J'ai mis en pièce jointe mon fichier de base avec les conseils de joe.levrai car visiblement le code de Quentin77170 ne fonctionne pas sur "If Not Target.Address = "$G$" & ligne Then" et j'arrive pas à trouver le couac.

    en effet, je préferais qu'il me note directement le résultat dans les colonnes I et T, plutôt que de réécrire la formule de calcul (pour trouver le résultat), mais mon premier choix n'a pas été réussi pour ma part

    Après une fois que cela fonctionnera, le but est de remplir 1 feuille par multiple de 4 personnes :
    1 feuille entre 1 et 4 personnes
    2 feuilles entre 5 et 8 personnes
    3 feuilles entre 9 et 12 personnes
    Pièces jointes en attente de validation Pièces jointes en attente de validation

  6. #6
    Expert éminent
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    3 898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

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

    Informations forums :
    Inscription : Avril 2002
    Messages : 3 898
    Points : 8 529
    Points
    8 529
    Par défaut
    Salut

    Le format de ton fichier semble poser problème, essaie de poster directement le fichier excel (ou un fichier .zip).

    ++
    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

  7. #7
    Membre du Club
    Homme Profil pro
    Derrière l'écran
    Inscrit en
    Novembre 2012
    Messages
    161
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Derrière l'écran

    Informations forums :
    Inscription : Novembre 2012
    Messages : 161
    Points : 68
    Points
    68
    Par défaut
    bonjour,

    ah désolé
    j'epère que cela devrait aller (en .xlsm et zip) : c'est le même

    Fichiers attachés Fichiers attachés

  8. #8
    Membre averti
    Homme Profil pro
    Ingénieur Industrialisation
    Inscrit en
    Mai 2015
    Messages
    222
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur Industrialisation
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2015
    Messages : 222
    Points : 412
    Points
    412
    Par défaut
    Salut à toi,

    Voici un moyen que je te propose pour n'avoir plus que 2 sous macros au lieu de 2 * 4 fois le même bout de code dans ta macro principale... On pourrait la réduire à 1 sous routine mais ça ne changerait pas grand chose, ça ferait juste avoir une sous routine plus lourde et chiante à comprendre !

    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
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Variables des différents tableaux 
    'PLUS NECESSAIRE EN L'ETAT
     
    t = Timer
     
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
     
    'Automatisation cellule 1er tableau (haut à gauche) éléments en heures
    Call test(8, 13, Range("C6"), Target)
     
    'Automatisation cellule 2ème tableau (haut à droite) éléments en heures
    Call test(8, 13, Range("N6"), Target)
     
    'Automatisation cellule 3ème tableau (bas à gauche) éléments en heures
    Call test(29, 34, Range("C29"), Target)
     
    'Automatisation cellule 4ème tableau (bas à droite) éléments en heures
    Call test(29, 34, Range("N29"), Target)
     
    'Automatisation cellule 1er tableau (haut à gauche) éléments en quantité
    Call test2(16, 22, Range("C6"), Target)
     
    'Automatisation cellule 2ème tableau (haut à droite) éléments en quantité
    Call test2(16, 22, Range("N6"), Target)
     
    'Automatisation cellule 3ème tableau (bas à gauche) éléments en quantité
    Call test2(39, 45, Range("C29"), Target)
     
    'Automatisation cellule 4ème tableau (bas à droite) éléments en quantité
    Call test2(39, 45, Range("N29"), Target)
     
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
     
    Debug.Print "Macro exécutée en : " & Timer - t & " secondes"
     
    End Sub
     
     
    Sub test(Début As Integer, Fin As Double, CelMatricule As Range, Target As Range)
     
    For ligne = Début To Fin
        If Target.Address <> "$G$" & ligne Then
            With Cells(ligne, CelMatricule.Column + 6)
                Select Case Cells(ligne, CelMatricule.Column + 4).Text
                    Case ""
                        .Value = ""
                    Case "Intervention astreinte jour"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!I:I;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
                    Case "Majoration férié travaillé"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!J:J;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Majoration de dimanche"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!K:K;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Majoration de nuit"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!L:L;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Intervention astreinte nuit"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!M:M;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Heures à 100%"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!N:N;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Heures à 110%"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!O:O;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")+SOMME.SI.ENS(Variables!S:S;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Heures à 125%"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!P:P;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")+SOMME.SI.ENS(Variables!Q:Q;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")+SOMME.SI.ENS(Variables!T:T;Variables!A:A;C6;Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Heures à 150%"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!R:R;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
                End Select
            End With
        End If
    Next
     
    End Sub
     
    Sub test2(Début As Integer, Fin As Double, CelMatricule As Range, Target As Range)
     
    For ligne = Début To Fin
        If Target.Address <> "$G$" & ligne Then
            With Cells(ligne, CelMatricule.Column + 6)
                Select Case Cells(ligne, CelMatricule.Column + 4).Text
                    Case ""
                        .Value = ""
     
                    Case "Panier jour taxable"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!F:F;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Indemnité astreinte dimanche"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!G:G;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Indemnité astreinte semaine"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!H:H;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Panier jour non taxable"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!U:U;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "Panier nuit non taxable", "Panier nuit taxable"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!V:V;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
     
                    Case "IPCM non taxable", "IPCM taxable"
                        .FormulaLocal = "=SOMME.SI.ENS(Variables!W:W;Variables!A:A;" & CelMatricule.Address & ";Variables!D:D;"">=""&" & CelMatricule.Offset(4).Address & ";Variables!D:D;""<=""&" & CelMatricule.Offset(5).Address & ")"
                End Select
            End With
        End If
    Next
     
    End Sub
    À partir de là, ça devient beaucoup plus simple de répéter ton code, peu importe le nombre de lignes et tout...

    Je me suis d'ailleurs permis d'enlever le calcul et le rafraîchissement en cours de macro, le temps gagné est juste non négligeable :
    Macro exécutée en : 0,0078125 secondes
    Macro exécutée en : 0,8710938 secondes
    La première ligne étant en désactivant le rafraîchissement + calcul, la seconde étant sans les désactiver !

    Quentin

  9. #9
    Expert éminent
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    3 898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

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

    Informations forums :
    Inscription : Avril 2002
    Messages : 3 898
    Points : 8 529
    Points
    8 529
    Par défaut
    Salut

    Alors à mon avis ton problème peut se résoudre sans l'utilisation de VBA, Excel est un tableau et les fonctions qu'il contient de base sont, une fois imbriquées, très puissantes.

    Il faut revoir un peu l'organisation de ton fichier. Je te donne un exemple de ce que je ferais mais tu peut trouver une autre organisation:

    1. Feuille "Tables" :
      • J'ajoute une colonne de plus au tableau qui se trouve en J:N, cette colonne je l'insère entre J et K (elle se nommera donc K dans la suite)
      • Je l'a rempli en notant la correspondance avec les entête du tableau se trouvant en feuille "Variables" (exemples: "Intervention astreinte jour" => "Inter. astreinte jour"; "Heures à 110%" => "HC 110%"; ....)

    2. Feuille "RH sur 1 mois" :
      • Je modifie les formule en colonne H et S : =SI(G9="";"";RECHERCHEV(G9;Tables!$J$1:$M$13;4;FAUX))
      • Je place la formule suivante en I et T : =SOMME.SI.ENS(DECALER(Variables!$A:$A;0;EQUIV(RECHERCHEV(G8;Tables!$J$1:$K$13;2;FAUX);Variables!$A$1:$W$1;0)-1);Variables!$A:$A;$C$6;Variables!$D:$D;">="&C$10;Variables!D:D;"<="&C11)
        • Cette formule devra être adapté un peu entre chaque tableau mais peut-être étendue avec la poignée en bas à droite dans chaque tableau (si je n'ai pas fait d'erreur d'écriture, il faudra contrôler avec des essais)
        • Il faudra englober cette cellule dans un "Si" pour contrôler si la cellule en G est vide ou si elle contient "Salaire de Base". Dans ce cas la formule doit renvoyer ""




    Bonne journée
    ++
    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. #10
    Membre du Club
    Homme Profil pro
    Derrière l'écran
    Inscrit en
    Novembre 2012
    Messages
    161
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Derrière l'écran

    Informations forums :
    Inscription : Novembre 2012
    Messages : 161
    Points : 68
    Points
    68
    Par défaut
    merci beaucoup cela fonctionne correctement.
    Il me reste plus qu'à faire la même chose avec 2 mois et des éléments sur 1 (l'un ou l'autre) ou 2 mois.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Utilisation d'une boucle dans une boucle
    Par caramon _majere dans le forum Langage
    Réponses: 5
    Dernier message: 27/09/2014, 21h37
  2. [XL-2003] faire une boucle dans une boucle VBA
    Par the-geut dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 27/04/2010, 15h06
  3. [PHP 5.0] Manipulation XML une boucle dans une boucle
    Par lepotier dans le forum Langage
    Réponses: 2
    Dernier message: 10/03/2010, 12h15
  4. [Tableaux] Boucle dans une boucle
    Par spawns dans le forum Langage
    Réponses: 2
    Dernier message: 12/02/2006, 13h11
  5. Creer une boucle dans une requête ???
    Par fdloisel dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 26/10/2004, 14h05

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