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 :

besoin d'une idée, d'une méthode pour réduire une procédure trop longue [XL-2007]


Sujet :

Macros et VBA Excel

  1. #1
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut besoin d'une idée, d'une méthode pour réduire une procédure trop longue
    Bonjour à tous,

    Novice en VBA je n'ai su faire autrement pour programmer un bouton qui agit sur une trentaine de lignes d'un classeur que de répéter 30 fois la même procédure la routine fonctionnée très bien jusqu'à ce que je rajoute quelques lignes pour les jours fériés. Il me faut encore rallonger la macro pour tenir compte de toutes les conditions, Alors j'ai besoin d'une méthode pour réduire la longueur de ma programmation
    Voici le code pour vous donnez une idée de la chose ; erreur de débutant j'en suis conscient mais pourtant cela fonctionner, hélas j'ai dépassé la limite autorisée tout d'abord il y a les fonction pour colorier

    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
    Private Declare Function ChooseColor Lib "comdlg32.dll" Alias _
        "ChooseColorA" (pChoosecolor As ChooseColor) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Type ChooseColor
             lStructSize As Long
             hwndOwner As Long
             hInstance As Long
             rgbResult As Long
             lpCustColors As String
             flags As Long
             lCustData As Long
             lpfnHook As Long
             lpTemplateName As String
    End Type
    encore une autre

    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
    Private Function ShowColor() As Long
    Dim ChooseColorStructure As ChooseColor
    Dim Custcolor(16) As Long
    Dim lReturn As Long
    ChooseColorStructure.lStructSize = Len(ChooseColorStructure)
    ChooseColorStructure.hwndOwner = FindWindow("XLMAIN", _
    Application.Caption)
    ChooseColorStructure.hInstance = 0
    ChooseColorStructure.lpCustColors = StrConv(CustomColors, _
    vbUnicode)
    ChooseColorStructure.flags = 0
    If ChooseColor(ChooseColorStructure) <> 0 Then
    ShowColor = ChooseColorStructure.rgbResult
    CustomColors = StrConv(ChooseColorStructure.lpCustColors, _
    vbFromUnicode)
    Else
    ShowColor = -1
    End If
    End Function
    puis la procédure

    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
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    Private Sub CommandButton1_Click()
    ActiveSheet.Unprotect
    Dim W As String
    Dim Début As Date
    Dim J As Double
    Dim F As Date
    Dim Compteur As Double
    Dim X As Range
    Dim ligne
    Dim colonne
    Début = DTPicker1.Value
    Dim Valeur As Double
     
    If Range("D7") = "" And _
           Range("D6") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G6:Zz6")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G7:Zz7")) > 0 Then
          Durée = Range("E7").Value
    J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(1, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ6").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ6").End(xlToLeft).Offset(-1, 0)
    Range("ZZ6").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz6").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ6").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz6").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Range("ZZ6").End(xlToLeft).Offset(0, 1).Select
    If ActiveCell.Interior.Color = 255 And Compteur < J Then
    MsgBox "rouge & VbOkOnly"
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ6").End(xlToLeft).Offset(0, 3) = 1
    End If
    Wend
    Range("zz6").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D8") = "" And _
           Range("D7") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G7:Zz7")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G8:Zz8")) > 0 Then
          Durée = Range("E7").Value
    J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(2, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ7").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ7").End(xlToLeft).Offset(-2, 0)
    Range("ZZ7").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz7").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ7").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz7").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Range("ZZ7").End(xlToLeft).Offset(0, 1).Select
    If ActiveCell.Interior.Color = 255 And Compteur < J Then
    MsgBox "rouge & VbOkOnly"
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ7").End(xlToLeft).Offset(0, 3) = 1
    End If
    Wend
    Range("zz7").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D9") = "" And _
           Range("D8") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G8:Zz8")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G9:Zz9")) > 0 Then
          Durée = Range("E8").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(3, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ8").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ8").End(xlToLeft).Offset(-3, 0)
    Range("ZZ8").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz8").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ8").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz8").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz8").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D10") = "" And _
           Range("D9") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G9:Zz9")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G10:Zz10")) > 0 Then
           Durée = Range("E9").Value
                 J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(4, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ9").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ9").End(xlToLeft).Offset(-4, 0)
    Range("ZZ9").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz9").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ9").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz9").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz9").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D11") = "" And _
           Range("D10") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G10:Zz10")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G11:Zz11")) > 0 Then
           Durée = Range("E10").Value
                 J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(5, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ10").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ10").End(xlToLeft).Offset(-5, 0)
    Range("ZZ10").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz10").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ10").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz10").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz10").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D12") = "" And _
           Range("D11") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G11:Zz11")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G12:Zz12")) > 0 Then
           Durée = Range("E11").Value
                        J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(6, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ11").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ11").End(xlToLeft).Offset(-6, 0)
    Range("ZZ11").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz11").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ11").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz11").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz11").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D13") = "" And _
           Range("D12") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G12:Zz12")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G13:Zz13")) > 0 Then
          Durée = Range("E12").Value
                        J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(7, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ12").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ12").End(xlToLeft).Offset(-7, 0)
    Range("ZZ12").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz12").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ12").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz12").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz12").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D14") = "" And _
           Range("D13") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G13:Zz13")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G14:Zz14")) > 0 Then
           Durée = Range("E13").Value
                               J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(8, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ13").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ13").End(xlToLeft).Offset(-8, 0)
    Range("ZZ13").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz13").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ13").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz13").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz13").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D15") = "" And _
           Range("D14") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G14:Zz14")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G15:Zz15")) > 0 Then
           Durée = Range("E14").Value
                               J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(9, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ14").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ14").End(xlToLeft).Offset(-9, 0)
    Range("ZZ14").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz14").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ14").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz14").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz14").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D16") = "" And _
           Range("D15") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G15:Zz15")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G16:Zz16")) > 0 Then
           Durée = Range("E15").Value
                                      J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(10, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ15").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ15").End(xlToLeft).Offset(-10, 0)
    Range("ZZ15").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz15").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ15").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz15").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz15").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D17") = "" And _
           Range("D16") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G16:Zz16")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G17:Zz17")) > 0 Then
           Durée = Range("E16").Value
                                      J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(11, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ16").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ16").End(xlToLeft).Offset(-11, 0)
    Range("ZZ16").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz16").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ16").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz16").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz16").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D18") = "" And _
           Range("D17") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G17:Zz17")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G18:Zz18")) > 0 Then
           Durée = Range("E17").Value
                                             J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(12, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ17").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ17").End(xlToLeft).Offset(-12, 0)
    Range("ZZ17").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz17").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ17").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz17").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz17").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D19") = "" And _
           Range("D18") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G18:Zz18")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G19:Zz19")) > 0 Then
           Durée = Range("E18").Value
                                             J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(13, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ18").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ18").End(xlToLeft).Offset(-13, 0)
    Range("ZZ18").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz18").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ18").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz18").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz18").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D20") = "" And _
           Range("D19") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G19:Zz19")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G20:Zz20")) > 0 Then
           Durée = Range("E19").Value
                                             J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(14, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ19").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ19").End(xlToLeft).Offset(-14, 0)
    Range("ZZ19").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz19").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ19").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz19").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz19").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D21") = "" And _
           Range("D20") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G20:Zz20")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G21:Zz21")) > 0 Then
           Durée = Range("E20").Value
    J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(15, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ20").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ20").End(xlToLeft).Offset(-15, 0)
    Range("ZZ20").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz20").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ20").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz20").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz20").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D22") = "" And _
           Range("D21") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G21:Zz21")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G22:Zz22")) > 0 Then
           Durée = Range("E21").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(16, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ21").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ21").End(xlToLeft).Offset(-16, 0)
    Range("ZZ21").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz21").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ21").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz21").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz21").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D23") = "" And _
           Range("D22") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G22:Zz22")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G23:Zz23")) > 0 Then
           Durée = Range("E22").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(17, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ22").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ22").End(xlToLeft).Offset(-17, 0)
    Range("ZZ22").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz22").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ22").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz22").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz22").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D24") = "" And _
           Range("D23") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G23:Zz23")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G24:Zz24")) > 0 Then
           Durée = Range("E23").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(18, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ23").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ23").End(xlToLeft).Offset(-18, 0)
    Range("ZZ23").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz23").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ23").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz23").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz23").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D25") = "" And _
           Range("D24") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G24:Zz24")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G25:Zz25")) > 0 Then
           Durée = Range("E24").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(19, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ24").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ24").End(xlToLeft).Offset(-19, 0)
    Range("ZZ24").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz24").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ24").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz24").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz24").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D26") = "" And _
           Range("D25") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G25:Zz25")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G26:Zz26")) > 0 Then
           Durée = Range("E25").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(20, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ25").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ25").End(xlToLeft).Offset(-20, 0)
    Range("ZZ25").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz25").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ25").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz25").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz25").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
     
     
    If Range("D27") = "" And _
           Range("D26") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G26:Zz26")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G27:Zz27")) > 0 Then
           Durée = Range("E26").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(21, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ26").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ26").End(xlToLeft).Offset(-21, 0)
    Range("ZZ26").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz26").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ26").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz26").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz26").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D28") = "" And _
           Range("D27") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G27:Zz27")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G28:Zz28")) > 0 Then
           Durée = Range("E27").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(22, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ27").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ27").End(xlToLeft).Offset(-22, 0)
    Range("ZZ27").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz27").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ27").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz27").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz27").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D29") = "" And _
           Range("D28") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G28:Zz28")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G29:Zz29")) > 0 Then
           Durée = Range("E28").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(23, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ28").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ28").End(xlToLeft).Offset(-23, 0)
    Range("ZZ28").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz28").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ28").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz28").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz28").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D30") = "" And _
           Range("D29") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G29:Zz29")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G30:Zz30")) > 0 Then
           Durée = Range("E29").Value
           J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(24, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ29").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ29").End(xlToLeft).Offset(-24, 0)
    Range("ZZ29").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz29").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ29").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz29").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz29").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D31") = "" And _
           Range("D30") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G30:Zz30")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G31:Zz31")) > 0 Then
           Durée = Range("E30").Value
           J = 0
    J = (Durée.Value * 2)
    End If
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(25, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ30").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ30").End(xlToLeft).Offset(-25, 0)
    Range("ZZ30").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz30").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ30").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz30").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz30").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D32") = "" And _
           Range("D31") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G31:Zz31")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G32:Zz32")) > 0 Then
            Durée = Range("E31").Value
                  J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(26, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ31").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ31").End(xlToLeft).Offset(-26, 0)
    Range("ZZ31").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz31").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ31").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz31").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz31").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D33") = "" And _
           Range("D32") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G32:Zz32")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G33:Zz33")) > 0 Then
            Durée = Range("E32").Value
                  J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(27, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ32").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ32").End(xlToLeft).Offset(-27, 0)
    Range("ZZ32").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz32").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ32").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz32").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz32").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D34") = "" And _
           Range("D33") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G33:Zz33")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G34:Zz34")) > 0 Then
            Durée = Range("E33").Value
                  J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(28, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ33").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ33").End(xlToLeft).Offset(-28, 0)
    Range("ZZ33").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz33").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ33").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz33").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz33").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D35") = "" And _
           Range("D34") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G34:Zz34")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G35:Zz35")) > 0 Then
           Durée = Range("E34").Value
                  J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(29, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ34").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ34").End(xlToLeft).Offset(-29, 0)
    Range("ZZ34").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz34").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ34").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz34").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz34").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D36") = "" And _
           Range("D35") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G35:Zz35")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G36:Zz36")) > 0 Then
            Durée = Range("E35").Value
                  J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(30, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ35").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ35").End(xlToLeft).Offset(-30, 0)
    Range("ZZ35").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz35").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ35").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz35").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz35").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    If Range("D36") <> "" Then
     Durée = Range("E36").Value
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(31, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ36").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ36").End(xlToLeft).Offset(-31, 0)
    Range("ZZ36").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz36").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ36").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz36").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz36").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    Unload UserForm1
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub
    en fait c'est ce code là qui est répété selon les condition en changeant les numéros de lignes et les décalages
    voici le dernier paragraphe qui traite la ligne 36

    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
    If Range("D36") <> "" Then
     Durée = Range("E36").Value
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(31, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ36").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ36").End(xlToLeft).Offset(-31, 0)
    Range("ZZ36").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz36").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ36").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz36").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Wend
    Range("zz36").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    Peu être que je pourrais mettre chaque paragraphe dans un module et les appelés selon les conditions, mais je ne sais pas comment m'y prendre

    merci pour votre aide

  2. #2
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut
    je vois que mon texte est tellement long qu'il n'y en a pas la moitié qui a passé

    voici un paragraphe qui est répéter 30 fois dans la procédure ; il faut absolument que je l'exporte ailleur ou que je n'utilise plus qu'un seul paragraphe en boucle mais comment lui faire changer de ligne à chaque fois ?
    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
    Private Sub CommandButton1_Click()
    ActiveSheet.Unprotect
    Dim W As String
    Dim Début As Date
    Dim J As Double
    Dim F As Date
    Dim Compteur As Double
    Dim X As Range
    Dim ligne
    Dim colonne
    Début = DTPicker1.Value
    Dim Valeur As Double
     
    If Range("D7") = "" And _
           Range("D6") <> "" _
           Or Application.WorksheetFunction.Sum(Range("G6:Zz6")) = 0 _
           And Application.WorksheetFunction.Sum(Range("G7:Zz7")) > 0 Then
          Durée = Range("E7").Value
    J = 0
    J = (Durée.Value * 2)
    ligne = 5
    colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
    colonne = colonne + 2
    ActiveSheet.Cells(ligne, colonne).Offset(1, 0) = 1
    If Durée = 0.5 Then
    Range("ZZ6").End(xlToLeft).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Compteur = 1
    While Compteur < J
    Compteur = Compteur + 1
    F = Range("ZZ6").End(xlToLeft).Offset(-1, 0)
    Range("ZZ6").End(xlToLeft).Offset(0, 1) = 1
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Range("zz6").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ6").End(xlToLeft).Offset(0, 5) = 1
    End If
    If W = "samedi" And Compteur = J Then
    Range("zz6").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    Exit Sub
    End If
    Range("ZZ6").End(xlToLeft).Offset(0, 1).Select
    If ActiveCell.Interior.Color = 255 And Compteur < J Then
    MsgBox "rouge & VbOkOnly"
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    MsgBox "La tâche n'est pas achevée !", vbOKOnly
    Range("ZZ6").End(xlToLeft).Offset(0, 3) = 1
    End If
    Wend
    Range("zz6").End(xlToLeft).Select
    Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
    Selection.Interior.Color = ShowColor
    End If
    merci

  3. #3
    Rédacteur/Modérateur

    Avatar de Jean-Philippe André
    Homme Profil pro
    Développeur VBA/C#/VB.Net/Power Platform
    Inscrit en
    Juillet 2007
    Messages
    14 594
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur VBA/C#/VB.Net/Power Platform
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2007
    Messages : 14 594
    Points : 34 266
    Points
    34 266
    Par défaut
    salut,

    on doit effectivement pouvoir placer tout ca dans une boucle For

    elle irait donc de i = 7 à 36

    attention, tes offsets me semble quelques peu compliqués, mais ca reste à toi de voir les améliorations

    indenter ton code est une nécessité pour le rendre visible aussi

    de la meme façon tu ne vas pas chercher Durée dans une cellule logique à chaque fois (un coup c'est dans la meme ligne, un coup dans la ligne d'avant... un sacré foutoir )

    tu peux partir sur une simplification de ce style :

    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
    For i = 7 to 36
     
    If Range("D" & i)  = "" And _
           Range("D" & i-1) <> "" _
           Or Application.WorksheetFunction.Sum(Range("G" & i-1 & ":Zz" & i-1)) = 0 _
           And Application.WorksheetFunction.Sum(Range("G" & i & ":Zz" & i)) > 0 Then
        Durée = Range("E" & i).Value
        J = 0
        J = (Durée.Value * 2)
        ligne = 5
        colonne = Application.Match(Me.DTPicker1 * 1, Rows(5))
        colonne = colonne + 2
        ActiveSheet.Cells(ligne, colonne).Offset(i-6, 0) = 1
        If Durée = 0.5 Then
            Range("ZZ" & i-1).End(xlToLeft).Select
            Selection.Interior.Color = ShowColor
            Exit Sub
        End If
        Compteur = 1
        While Compteur < J
            Compteur = Compteur + 1
            F = Range("ZZ" & i-1).End(xlToLeft).Offset(- 1* (i-6), 0)
            Range("ZZ" & i-1).End(xlToLeft).Offset(0, 1) = 1
            W = WeekdayName(Weekday(F))
            If W = "samedi" And Compteur < J Then
                Range("zz" & i-1).End(xlToLeft).Select
                Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
                Selection.Interior.Color = ShowColor
                MsgBox "La tâche n'est pas achevée !", vbOKOnly
                Range("ZZ" & i-1).End(xlToLeft).Offset(0, 5) = 1
            End If
            If W = "samedi" And Compteur = J Then
                Range("zz" & i-1).End(xlToLeft).Select
                Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
                Selection.Interior.Color = ShowColor
                Exit Sub
            End If
            Range("ZZ" & i-1).End(xlToLeft).Offset(0, 1).Select
            If ActiveCell.Interior.Color = 255 And Compteur < J Then
                MsgBox "rouge & VbOkOnly"
                Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
                Selection.Interior.Color = ShowColor
                MsgBox "La tâche n'est pas achevée !", vbOKOnly
                Range("ZZ" & i-1).End(xlToLeft).Offset(0, 3) = 1
            End If
        Wend
        Range("zz" & i-1).End(xlToLeft).Select
        Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
        Selection.Interior.Color = ShowColor
    End If
     
     
    Next i
    Cycle de vie d'un bon programme :
    1/ ça fonctionne 2/ ça s'optimise 3/ ça se refactorise

    Pas de question technique par MP, je ne réponds pas

    Mes ouvrages :
    Apprendre à programmer avec Access 2016, Access 2019 et 2021

    Apprendre à programmer avec VBA Excel
    Prise en main de Dynamics 365 Business Central

    Pensez à consulter la FAQ Excel et la FAQ Access

    Derniers tutos
    Excel et les paramètres régionaux
    Les fichiers Excel binaires : xlsb,

    Autres tutos

  4. #4
    Expert éminent sénior Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Points : 31 877
    Points
    31 877
    Par défaut
    Si ton bloc se répète pour chaque ligne, il suffit de créer une procédure avec comme paramètre ta ligne
    Exemple (à adapter selon ton besoin)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub Traiter(ByVal Lig As Integer)
     
    If Range("D" & Lig) <> "" Then
        Durée = Range("E" & Lig).Value
        J = (Durée.Value * 2)
        ligne = 5
    '....
    End Sub
    et dans ton code principal, tu crée un boucle d'appel

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    For j=6 To 100
           Call Traiter(i)
    Next i
    PS: Évites tes Select et Activemachin, ils ne sont pas nécessaires. Tu as du travail pour assainir ton code
    Cordialement.
    J'utilise toujours le point comme séparateur décimal dans mes tests.

  5. #5
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut
    merci beaucoup
    je ne savais pas comment m'y prendre pour changer de ligne sans réecrire le paragraphe et tu me tires une belle épine du pied
    Quand à faire compliquer quand on peu faire simple, je pense que c'est le propre du débutant ; je le répète toujours à mes élèves : Mouarf: mais je ne leur fais pas voir mes "exploits"

    merci encore je vais sauver ma feuille et recommencer avec ta méthode : Ccool:

    merci à tous là je crois que j'ai du travail pour quelques jours d'ici que je comprenne tout : Aie: mais c'est le but : Ccool:

  6. #6
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    12 764
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur, développeur et consultant Excel, Access, Word et VBA

    Informations forums :
    Inscription : Janvier 2010
    Messages : 12 764
    Points : 28 622
    Points
    28 622
    Billets dans le blog
    53
    Par défaut
    Bonjour,
    Je sais que c'est résolu mais j'ai encore une petite remarque que je t'avais signalée il y a presqu'un mois dans un de tes premiers posts, en te demandant pourquoi tu testais "Samedi" plutôt que directement le numéro de la semaine
    Il y d'ailleurs un gros problème dans ta fonction parce-que tu as omis de préciser la valeur du deuxième argument et sauf erreur de ma part, il ne risque pas de trouver un véritable samedi.

    Ton code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    W = WeekdayName(Weekday(F))
    If W = "samedi" And Compteur < J Then
    Regarde avec les deux codes ci-dessous, le 28/07/2012 est un samedi. avec le premier code il le considère comme un dimanche et c'est ce code que tu utilises.
    Code avec mauvais test

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Sub t()Dim f As Date, w As String
     f = "28/07/2012"
     w = WeekdayName(Weekday(f))
     If w = "samedi" Then MsgBox "C'est un samedi"
     If w = "vendredi" Then MsgBox "C'est un vendredi"
     If w = "dimanche" Then MsgBox "C'est un dimanche"
    End Sub
    Code avec bon test
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Sub t1()
     Dim f As Date
     f = "28/07/2012"
     If Weekday(f, vbMonday) = 6 Then MsgBox "C'est un samedi"
    End Sub
    La fonction Weekday() est la même que JOURSEM dans la version française d'Excel et Weekday dans sa version anglaise, si le deuxième argument n'est pas précisé, il considère dimanche comme premier jour.
    Une bonne connaissance des fonctions d'excel est un atout considérable pour programmer en VBA pour Excel.
    Philippe Tulliez
    Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)
    Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
    Mes tutoriels : Utilisation de l'assistant « Insertion de fonction », Les filtres avancés ou élaborés dans Excel
    Mon dernier billet : Utilisation de la fonction Dir en VBA pour vérifier l'existence d'un fichier

  7. #7
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2012
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2012
    Messages : 317
    Points : 101
    Points
    101
    Par défaut
    C'est extra la macro fonctionne bien malgré une petite erreur à la fin que j'ai traité avec une étiquette "honte à moi " : Oops: Ce qui me chagrine est que c'est le travail d'un autre mais d'un autre côté ça me fait progresser petit à petit et à l'automne je vais pouvoir épater les stagiaires qui parfois ne savent même pas démarrer excel : Mouarf:
    mais bon moi aussi j'ai encore une montagne de chose à apprendre, c'est pour ça que c'est beau la vie : on ne sais jamais tout et merci à vous pour votre implication, disponibilité et gentillesse

    A+

    Didier

    merci Philippe de me recadrer encore une fois ton code est beaucoup plus simple que le mien et je vais l'utiliser sans remord, mais avec mon code de débutant je trouvais bien les samedi car je je me suis inspirer des formules classique et j'ai tenu compte de la méthode Américaine dans la macro qui écrit le calendrier et ça fonctionne très bien même si ce n'est pas beau. Je' vais tenir compte de ton conseil mais je vais aussi sans doute devoir modifier ma macro calendrier

    Merci à tous

  8. #8
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    12 764
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur, développeur et consultant Excel, Access, Word et VBA

    Informations forums :
    Inscription : Janvier 2010
    Messages : 12 764
    Points : 28 622
    Points
    28 622
    Billets dans le blog
    53
    Par défaut
    Bonjour Didier,
    Le plus intéressant surtout de travailler avec le numéro du jour plutôt qu'avec la chaîne de caractères de son nom, c'est d'une part d'éviter les problèmes de tomber sur quelqu'un qui aurait une version autre que française et d'autre part de tester le week-end par un simple If Weekday(f, vbMonday) >5 then ou <6 pour les jours de semaine.
    Philippe Tulliez
    Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)
    Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
    Mes tutoriels : Utilisation de l'assistant « Insertion de fonction », Les filtres avancés ou élaborés dans Excel
    Mon dernier billet : Utilisation de la fonction Dir en VBA pour vérifier l'existence d'un fichier

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

Discussions similaires

  1. Recherche méthode pour formater une chaine pour JS
    Par mittim dans le forum Langage
    Réponses: 1
    Dernier message: 05/09/2006, 10h04
  2. Méthode pour dimensionner une architecture ?
    Par ericlemoustic dans le forum Autres
    Réponses: 3
    Dernier message: 11/05/2006, 16h14
  3. Méthode pour marquer une carte
    Par Space Cowboy dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 27/03/2006, 13h15
  4. Méthode pour inclure une langue
    Par HwRZxLc4 dans le forum Langage
    Réponses: 14
    Dernier message: 20/03/2006, 09h22
  5. [SWING][THREAD]Méthodes pour afficher une Frame
    Par pompidouwa dans le forum Agents de placement/Fenêtres
    Réponses: 3
    Dernier message: 05/05/2004, 10h35

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