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 :

Code à Adapter


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 4
    Par défaut Code à Adapter
    Bonjour,

    Je suis jeune, innocent et assez nouveau avec le Visual Basic (3 semaines à peu près) donc peace si le code est pas vraiment optimal xD.

    Alors je vous explique à quoi sert ce code : En fait, il exploite un fichier Excel exporté d'une plateforme d'échange de plan AutoCAD appelée e-DOC. Ce fichier exporté a des colonnes types (Émetteur, Types, Date d'indice etc ...) mais dont l'agencement est pas fixe, donc je me suis servi de ces Titres de Colonne (avec la fonction recherche) pour capter les infos dont j'ai besoin et recréer un tableau dans un nouvelle onglet avec les informations essentielles rangées dans un certain ordre. un onglet est crée pour chaque couple d’Émetteur et Type.

    Ce que je voudrais, c'est créer un fichier vierge Excel contenant la macro dont je vous parle avec un bouton la lançant. En cliquant sur le bouton on importerait les données du fichier Excel exporté de e-Doc et on lancerais la procédure de "rangement". Parce que je dois copier coller le code à chaque fois dans le fichier à exploiter ...

    En fait j'ai été surpris par le Excel 2007, parce qu'avant quand on ouvrait un fichier, il s'ouvrait dans la fenêtre active alors que maintenant il s'ouvre dans une fenêtre différente donc je me demande si ActiveSheet est à l'origine de mon erreur 1004 quand je lance ma macro en "Macro Complémentaire"

    Merci d'avance,
    Cdlt, Remmanso

    PS : Les données du document ont toutes été modifiées pour qu'il n'y ait pas de petits malins qui me posent des problèmes (les données sont confidentielles) :p

    PS2: si vous avez des conseilles pour optimiser mon code, ils seront les bienvenues
    Fichiers attachés Fichiers attachés

  2. #2
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2012
    Messages : 4
    Par défaut
    je vous rajoute le code pour que vous n'ayez pas à télécharger le fichier pour m'aider ( et j'en profite un tout petit peu pour up aussi )

    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
     
    Sub Tri_Excel()
     
    '****************************************************
    '*                                                  *
    '*                  Version Beta.                   *
    '*     Pour toutes questions: Remmanso@gmail.com    *
    '*                                                  *
    '*                                                  *
    '****************************************************
     
     
        Dim Wcible As String
        Dim Ws As Worksheet
        Dim Wsource As String
        Dim i_min As Integer
        Dim i_max As Integer
        Dim i As Integer
        Dim tablo0() As String
        Dim tablo1() As String
        Dim tabloX() As String
        Dim tabloS() As String
        Dim tabloR() As String
        Dim tabloRD() As String
        Dim tablo() As String
        Dim Dtp As Date
        Dim Dtr As Date
     
     
        Wsource = ActiveSheet.Name
     
                                    'Définition des Colonnes et Lignes Repères.
     
        Cells.Find(What:="Reçu le", After:=ActiveCell, LookIn:=xlFormulas, lookat:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=True).Activate
            Recol = ActiveCell.Column
     
        Cells.Find(What:="Date indice", After:=ActiveCell, LookIn:=xlFormulas, lookat:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=True).Activate
            Dicol = ActiveCell.Column
     
        Cells.Find(What:="BAT ZONE", After:=ActiveCell, LookIn:=xlFormulas, lookat:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=True).Activate
            Bzcol = ActiveCell.Column
     
        Cells.Find(What:="NUMERO", After:=ActiveCell, LookIn:=xlFormulas, lookat:=1, SearchOrder:=xlByColumns, _
        SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=True).Activate
            Nucol = ActiveCell.Column
     
        Cells.Find(What:="Indice", After:=ActiveCell, LookIn:=xlFormulas, lookat:=1, SearchOrder:=xlByColumns, _
        SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=True).Activate
            Icol = ActiveCell.Column
     
        Cells.Find(What:="NIVEAU", After:=ActiveCell, LookIn:=xlFormulas, lookat:=1, SearchOrder:=xlByColumns, _
        SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=True).Activate
            Ncol = ActiveCell.Column
            Nrow = ActiveCell.Row
     
        Cells.Find(What:="EMETTEUR", After:=ActiveCell, LookIn:=xlFormulas, lookat:=1, SearchOrder:=xlByColumns, _
        SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=True).Activate
            Ecol = ActiveCell.Column
     
        Cells.Find(What:="TYPE", After:=ActiveCell, LookIn:=xlFormulas, lookat:=1, SearchOrder:=xlByColumns, _
        SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=True).Activate
            Tcol = ActiveCell.Column
     
                                    '1er tri de la colonne NIVEAU
     
        m = Nrow + 1
     
        ReDim tabloX(Cells(65536, Ncol).End(xlUp).Row - m, 7 To 8)
     
        ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Clear
        ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Add Key:=Range(Cells(Nrow, Tcol), Cells(Cells(65536, Recol).End(xlUp).Row, Tcol)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortTextAsNumbers
        With ActiveWorkbook.Worksheets(Wsource).Sort
            .SetRange Range("A" & Nrow, "GA" & Cells(65536, Ncol).End(xlUp).Row)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
     
        i = 0
        Do
            If Cells(m, Tcol).Value <> Cells(m + 1, Tcol).Value Then
                tabloX(i, 8) = Cells(m, Tcol)
                i = i + 1
            End If
                m = m + 1
        Loop Until m > Cells(65536, Ncol).End(xlUp).Row
        Tmax = i
        m = Nrow + 1
     
        ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Clear
        ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Add Key:=Range(Cells(Nrow, Ecol), Cells(Cells(65536, Recol).End(xlUp).Row, Ecol)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortTextAsNumbers
        With ActiveWorkbook.Worksheets(Wsource).Sort
            .SetRange Range("A" & Nrow, "GA" & Cells(65536, Ncol).End(xlUp).Row)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
     
        i = 0
        Do
            If Cells(m, Ecol).Value <> Cells(m + 1, Ecol).Value Then
                tabloX(i, 7) = Cells(m, Ecol)
                i = i + 1
            End If
                m = m + 1
        Loop Until m > Cells(65536, Ncol).End(xlUp).Row
        Emax = i
     
    For t = 0 To Emax
    For c = 0 To Tmax
     
        m = Nrow + 1
        ReDim tablo1(Worksheets(Wsource).Cells(65536, Ncol).End(xlUp).Row - m, 1 To 8)
     
        ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Clear
        ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Add Key:=Range(Cells(Nrow, Ncol), Cells(Cells(65536, Ncol).End(xlUp).Row, Ncol)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortTextAsNumbers
        With ActiveWorkbook.Worksheets(Wsource).Sort
            .SetRange Range("A" & Nrow, "GA" & Cells(65536, Ncol).End(xlUp).Row)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
     
        For k = 0 To Cells(65536, Ncol).End(xlUp).Row - m
                    tablo1(k, 7) = Cells(Nrow + k + 1, Ecol)
        Next
        For k = 0 To Cells(65536, Ncol).End(xlUp).Row - m
                    tablo1(k, 8) = Cells(Nrow + k + 1, Tcol)
        Next
     
                                    'Definition des tableaux
     
            ReDim tablo(Cells(65536, Ncol).End(xlUp).Row - Nrow)
            ReDim tablo0(Cells(65536, Ncol).End(xlUp).Row - Nrow)
            ReDim tabloS(Cells(65536, Ncol).End(xlUp).Row - Nrow)
            ReDim tabloR(Cells(65536, Ncol).End(xlUp).Row - Nrow)
            ReDim tabloRD(Cells(65536, Ncol).End(xlUp).Row - Nrow)
     
     
                                    'Remplissage des tableaux
     
     
                m = Nrow + 1
                o = 0
                For k = 0 To Cells(65536, Ncol).End(xlUp).Row - m
                    If tablo1(k, 7) = tabloX(t, 7) And tablo1(k, 8) = tabloX(c, 8) Then
                    tablo1(o, 1) = ActiveWorkbook.Worksheets(Wsource).Cells(Nrow + k + 1, Ncol)
                    o = o + 1
                    End If
                Next
                o = 0
                For k = 0 To Cells(65536, Ncol).End(xlUp).Row - m
                    If tablo1(k, 7) = tabloX(t, 7) And tablo1(k, 8) = tabloX(c, 8) Then
                    tablo1(o, 2) = ActiveWorkbook.Worksheets(Wsource).Cells(Nrow + k + 1, Icol)
                    o = o + 1
                End If
                Next
                o = 0
                For k = 0 To Cells(65536, Ncol).End(xlUp).Row - m
                    If tablo1(k, 7) = tabloX(t, 7) And tablo1(k, 8) = tabloX(c, 8) Then
                    tablo1(o, 3) = ActiveWorkbook.Worksheets(Wsource).Cells(Nrow + k + 1, Nucol)
                    o = o + 1
                    End If
                Next
                o = 0
                For k = 0 To Cells(65536, Ncol).End(xlUp).Row - m
                    If tablo1(k, 7) = tabloX(t, 7) And tablo1(k, 8) = tabloX(c, 8) Then
                    tablo1(o, 4) = ActiveWorkbook.Worksheets(Wsource).Cells(Nrow + k + 1, Bzcol)
                    o = o + 1
                    End If
                Next
                o = 0
                For k = 0 To Cells(65536, Ncol).End(xlUp).Row - m
                    If tablo1(k, 7) = tabloX(t, 7) And tablo1(k, 8) = tabloX(c, 8) Then
                    tablo1(o, 5) = ActiveWorkbook.Worksheets(Wsource).Cells(Nrow + k + 1, Dicol)
                    o = o + 1
                    End If
                Next
                o = 0
                For k = 0 To Cells(65536, Ncol).End(xlUp).Row - m
                    If tablo1(k, 7) = tabloX(t, 7) And tablo1(k, 8) = tabloX(c, 8) Then
                    tablo1(o, 6) = ActiveWorkbook.Worksheets(Wsource).Cells(Nrow + k + 1, Recol)
                    o = o + 1
                    End If
                Next
                o = 0
                'For k = 0 To Application.WorksheetFunction.Max(Emax, Tmax)
                    'Worksheets(Wsource).Cells(25 + k, 1).Select
                    'Worksheets(Wsource).Cells(25 + k, 1) = tabloX(k, 7)
                    'Worksheets(Wsource).Cells(25 + k, 2).Select
                    'Worksheets(Wsource).Cells(25 + k, 2) = tabloX(k, 8)
               ' Next
     
                                    'Ignorement des Doublons.
                j = 0
                i = 0
                Do
                    If tablo1(m - Nrow - 1, 7) = tabloX(t, 7) And tablo1(m - Nrow - 1, 8) = tabloX(c, 8) Then
                        tablo(i) = ActiveWorkbook.Worksheets(Wsource).Cells(m, Ncol)
                        If tablo(i) <> tablo(i + 1) Then
                        tablo0(j) = tablo(i)
                        j = j + 1
                        End If
                        i = i + 1
                    End If
                    m = m + 1
                Loop Until m > ActiveWorkbook.Worksheets(Wsource).Cells(65536, Ncol).End(xlUp).Row
     
    If tablo0(0) <> "" Then
                                    'Remplissage des etages
     
                RD = 1
                R = 1
                S = 1
                For j = 0 To Cells(65536, Ncol).End(xlUp).Row - Nrow
     
                    If Mid(tablo0(j), 1, 1) = "S" Or Mid(tablo0(j), 1, 2) = "R-" Or Mid(tablo0(j), 1, 3) = "NI-" Then
                        tabloS(S) = tablo0(j)
                        S = S + 1
     
                    ElseIf Mid(tablo0(j), 1, 2) = "RD" Or Mid(tablo0(j), 1, 2) = "RC" Then
                        tabloRD(RD) = tablo0(j)
                        RD = RD + 1
     
                    ElseIf Mid(tablo0(j), 1, 2) = "R+" Or Mid(tablo0(j), 1, 3) = "NI+" Or Mid(tablo0(j), 1, 3) = "N+" Then
                        tabloR(R) = tablo0(j)
                        R = R + 1
     
                    ElseIf (Mid(tablo0(j), 1, 1) = "R" And Mid(tablo0(j), 1, 2) <> "R+" And Mid(tablo0(j), 1, 2) <> "R-") Or (Mid(tablo0(j), 1, 1) = "E") Or (Mid(tablo0(j), 1, 1) = "N" And Mid(tablo0(j), 1, 2) <> "NI+" _
                    And Mid(tablo0(j), 1, 2) <> "NI-" And Mid(tablo0(j), 1, 2) <> "N+" And Mid(tablo0(j), 1, 2) <> "N-") Then
                        tabloR(R) = tablo0(j)
                        R = R + 1
     
                    End If
                Next
     
     
                                    'Redéfinition des tableaux R et S sous condition
     
                If S <> 1 Then
                ReDim Preserve tabloS(S - 1)
                Else: ReDim tabloS(0)
                End If
     
                If R <> 1 Then
                ReDim Preserve tabloR(R - 1)
                Else: ReDim tabloR(0)
                End If
     
                If RD <> 1 Then
                ReDim Preserve tabloRD(RD - 1)
                Else: ReDim tabloRD(0)
                End If
     
                                    'Dernier tri des étages et remplissage des Tableaux R et S
     
                Application.ScreenUpdating = False
                Columns(3).Insert
                Columns(3).Insert
                Columns(3).Insert
                Columns(3).Insert
     
                ActiveWorkbook.Worksheets(Wsource).Range("D:D,F:F").NumberFormat = "@"
     
                LBS = LBound(tabloS)
                UBS = UBound(tabloS)
                LBRD = LBound(tabloRD)
                UBRD = UBound(tabloRD)
                LBR = LBound(tabloR)
                UBR = UBound(tabloR)
     
                For N = LBS To UBS
                For m = 1 To Len(Mid(tabloS(N), 1))
                    If IsNumeric(Mid(tabloS(N), m, 1)) Then
                        ActiveWorkbook.Worksheets(Wsource).Range("D" & N + 1) = ActiveWorkbook.Worksheets(Wsource).Range("D" & N + 1).Value & Mid(tabloS(N), m, 1)
                        Else: ActiveWorkbook.Worksheets(Wsource).Range("C" & N + 1) = ActiveWorkbook.Worksheets(Wsource).Range("C" & N + 1) & Mid(tabloS(N), m, 1)
                    End If
                Next m
                Next N
     
                For N = LBR To UBR
                For m = 1 To Len(Mid(tabloR(N), 1))
                    If IsNumeric(Mid(tabloR(N), m, 1)) Then
                        ActiveWorkbook.Worksheets(Wsource).Range("F" & N + 1).Value = ActiveWorkbook.Worksheets(Wsource).Range("F" & N + 1).Value & Mid(tabloR(N), m, 1)
                    Else: ActiveWorkbook.Worksheets(Wsource).Range("E" & N + 1) = ActiveWorkbook.Worksheets(Wsource).Range("E" & N + 1) & Mid(tabloR(N), m, 1)
                    End If
                Next m
                 Next N
     
               With Worksheets(Wsource)
                ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Clear
                ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Add Key:=Range("F1:F" & UBR + 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
                xlSortTextAsNumbers
                With ActiveWorkbook.Worksheets(Wsource).Sort
                    .SetRange Range("E1:F" & UBR + 1)
                    .Header = xlNo
                    .MatchCase = False
                    .Orientation = xlTopToBottom
                    .SortMethod = xlPinYin
                    .Apply
                End With
     
                ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Clear
                ActiveWorkbook.Worksheets(Wsource).Sort.SortFields.Add Key:=Range("C1:C" & UBS + 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
                xlSortTextAsNumbers
                With ActiveWorkbook.Worksheets(Wsource).Sort
                    .SetRange Range("C1:D" & UBS + 1)
                    .Header = xlNo
                    .MatchCase = False
                    .Orientation = xlTopToBottom
                    .SortMethod = xlPinYin
                    .Apply
                End With
     
                For N = LBS To UBS
                    tabloS(N) = ActiveWorkbook.Worksheets(Wsource).Range("C" & N + 1) & Range("D" & N + 1)
                Next N
     
                For N = LBR To UBR
                    tabloR(N) = ActiveWorkbook.Worksheets(Wsource).Range("E" & N + 1) & Range("F" & N + 1)
                Next N
                Worksheets(Wsource).Columns("C:F").Delete
                End With
                Application.ScreenUpdating = True
     
                                    'Création du tableau dans une nouvelle feuille
     
     
     
                    Wcible = tabloX(t, 7) & ", " & tabloX(c, 8)
                'InputBox("Veuillez entrer le nom que vous souhaitez pour une nouvelle feuille Excel.", _
                "Nouvelle Feuille", "Sans Titre")
     
     
                Application.DisplayAlerts = False
                For Each Ws In ActiveWorkbook.Worksheets
                        If Ws.Name = Wcible Then
                            Ws.Delete
                            Exit For
                        End If
                Next
     
                Application.DisplayAlerts = True
                Sheets.Add.Name = Wcible
                Worksheets(Wcible).Select
     
     
                                    'Remplissage ligne Niveaux dans l'ordre
     
                X = 4
                If UBS <> 0 Then
                    k = LBS
                    Do
                        k = k + 1
                        ActiveSheet.Range(Sheets(Wcible).Cells(4, X), Sheets(Wcible).Cells(4, X + 1)).Select
                        Selection.Merge
                        Selection.Font.Bold = True
                        Sheets(Wcible).Cells(4, X).Value = tabloS(UBS - k)
                        X = X + 2
                    Loop Until k >= UBS
                    i = 1
                Else: i = 0
                End If
     
                If UBRD <> 0 Then
                    k = UBS + i
                    Do
                        ActiveSheet.Range(Sheets(Wcible).Cells(4, X), Sheets(Wcible).Cells(4, X + 1)).Select
                        Selection.Merge
                        Selection.Font.Bold = True
                        Sheets(Wcible).Cells(4, X).Value = tabloRD(UBRD - (k - (UBS + i)))
                        X = X + 2
                        k = k + 1
                    Loop Until k >= UBS + UBRD + i
                    j = 0
                Else: j = -1
                End If
     
                If UBR <> 0 Then
                    k = UBS + UBRD + i + j
                    Do
                        ActiveSheet.Range(Sheets(Wcible).Cells(4, X), Sheets(Wcible).Cells(4, X + 1)).Select
                        Selection.Merge
                        Selection.Font.Bold = True
                        Sheets(Wcible).Cells(4, X).Value = tabloR(k - (UBS + UBRD + i + j))
                        X = X + 2
                        k = k + 1
                    Loop Until k >= UBS + UBRD + i + j + UBR
                End If
                X = X - 1
     
                ActiveSheet.Range(Sheets(Wcible).Cells(3, 4), Sheets(Wcible).Cells(3, X)).Select
                        With Selection
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        End With
                        Selection.Merge
                        Selection.Font.Bold = True
                ActiveCell.Value = "Niveaux"
     
                                    'Génération des colonnes Prévu & Réalisé
     
                For k = 4 To X Step 2
                    Sheets(Wcible).Cells(5, k) = "Prévu"
                    Sheets(Wcible).Cells(5, k + 1) = "Réalisé"
                Next
     
                                    'Création & Remplissage colonne Zone
     
                        ActiveSheet.Range(Sheets(Wcible).Cells(3, 1), Sheets(Wcible).Cells(5, 1)).Select
                        With Selection
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        End With
                        Selection.Merge
                        Selection.Font.Bold = True
                        ActiveCell.Value = "Zone"
     
                        p = 6
                        l = 0
                        Sheets(Wcible).Cells(6, 1) = tablo1(0, 4)
                        Do
                        'And tablo1(l, 7) = tabloX(t, 7) And tablo1(l, 8) = tabloX(c, 8)
                            If tablo1(l, 4) <> tablo1(l + 1, 4) Then
                                Sheets(Wcible).Cells(p + 1, 1) = tablo1(l + 1, 4)
                            ElseIf tablo1(l, 4) = tablo1(l + 1, 4) And tablo1(l, 4) <> "" Then
                                ActiveSheet.Range(Sheets(Wcible).Cells(p, 1), Sheets(Wcible).Cells(p + 1, 1)).Select
                                With Selection
                                .HorizontalAlignment = xlCenter
                                .VerticalAlignment = xlCenter
                                End With
                                Selection.Merge
                            End If
     
                            l = l + 1
                            p = p + 1
                        Loop Until l >= Sheets(Wsource).Cells(65536, Ncol).End(xlUp).Row - Nrow - 1
     
                                    'Création & Remplissage colonne Numéro
     
                        ActiveSheet.Range(Sheets(Wcible).Cells(3, 2), Sheets(Wcible).Cells(5, 2)).Select
                        With Selection
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        End With
                        Selection.Merge
                        Selection.Font.Bold = True
                        ActiveCell.Value = "Numéro"
     
                        For k = 0 To Cells(65536, Ncol).End(xlUp).Row - Nrow - 1
                            Sheets(Wcible).Cells(k + 6, 2) = tablo1(k, 3)
                        Next
     
                                    'Création & Remplissage colonne Indice
     
                        ActiveSheet.Range(Sheets(Wcible).Cells(3, 3), Sheets(Wcible).Cells(5, 3)).Select
                        With Selection
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        End With
                        Selection.Merge
                        Selection.Font.Bold = True
                        ActiveCell.Value = "Indice"
     
                        For k = 0 To Cells(65536, Ncol).End(xlUp).Row - Nrow - 1
                            Sheets(Wcible).Cells(k + 6, 3) = tablo1(k, 2)
                        Next
     
                                    'Rayure du tableau en Gris
                        If Sheets(Wcible).Cells(65536, 2).End(xlUp).Row > 6 Then
     
                        For l = 0 To Sheets(Wcible).Cells(65536, 1).End(xlUp).Row - 5 Step 2
                            ActiveSheet.Range(Sheets(Wcible).Cells(l + 7, 2), Sheets(Wcible).Cells(l + 7, X)).Interior.ColorIndex = "15"
                        Next
     
                        End If
                                    'Remplissage Prévu & Réalisé et comparaison si Retard
     
                        w = 0
                        v = 0
                        Do
                            A = 0
                            Do
                            Do
                                If Sheets(Wcible).Cells(4, 4 + v).Value = tablo1(A, 1) And Sheets(Wcible).Cells(6 + w, 2).Value = tablo1(A, 3) Then
                                        Sheets(Wcible).Cells(6 + w, 4 + v) = tablo1(A, 5)
                                        Sheets(Wcible).Cells(6 + w, 5 + v) = tablo1(A, 6)
                                        Dtp = tablo1(A, 5)
                                        Dtr = tablo1(A, 6)
                                        If Dtp - Dtr < 0 Then
                                                    Sheets(Wcible).Cells(6 + w, 4 + v).Interior.ColorIndex = 3
                                                    Sheets(Wcible).Cells(6 + w, 5 + v).Interior.ColorIndex = 3
                                        End If
                                Exit Do
                                Else:
                                        Sheets(Wcible).Cells(6 + w, 4 + v) = "XXXXXXXXX"
                                        Sheets(Wcible).Cells(6 + w, 5 + v) = "XXXXXXXXX"
                                End If
                                A = A + 1
                            Loop Until A = Sheets(Wcible).Cells(65536, 2).End(xlUp).Row - 5
                            'Sheets(Wsource).Cells(65536, Ncol).End(xlUp).Row -Nrow
                            A = 0
                            w = w + 1
                            Loop Until w = Sheets(Wcible).Cells(65536, 2).End(xlUp).Row - 5
                            'Sheets(Wsource).Cells(65536, Ncol).End(xlUp).Row - Nrow
                            w = 0
                            v = v + 2
                        Loop Until v >= X - 3
     
                                    'Création des contours du Tableau
     
                        Sheets(Wcible).Cells.Select
                        With Selection
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        End With
     
                        For h = Sheets(Wcible).Cells(1, 1).End(xlDown).Row To Sheets(Wcible).Cells(Sheets(Wcible).Cells(65536, 1).End(xlUp).Row, 1).Row
                            ActiveSheet.Range(Sheets(Wcible).Cells(h, 1), Sheets(Wcible).Cells(h, X)).Select
                                With Selection.Borders(xlEdgeLeft)
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                                End With
                                With Selection.Borders(xlEdgeTop)
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                                End With
                                With Selection.Borders(xlEdgeBottom)
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                                End With
                                With Selection.Borders(xlEdgeRight)
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                                End With
                        Next
     
                        For j = 0 To X
     
                            If j = 0 Then
                                Sheets(Wcible).Cells(3, 4).Select
                            Else: lo = Sheets(Wcible).Cells(Sheets(Wcible).Cells(65536, j).End(xlUp).Row, j).Row
                            End If
     
                            If j = 4 Then
                                ActiveSheet.Range(Sheets(Wcible).Cells(4, 4), Sheets(Wcible).Cells(4, X)).Select
                            ElseIf j <> 0 And j <> 4 Then
                                hi = Sheets(Wcible).Cells(2, j).End(xlDown).Row
                                ActiveSheet.Range(Sheets(Wcible).Cells(hi, j), Sheets(Wcible).Cells(lo, j)).Select
                            End If
     
                                With Selection.Borders(xlEdgeLeft)
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                                End With
                                With Selection.Borders(xlEdgeTop)
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                                End With
                                With Selection.Borders(xlEdgeBottom)
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                                End With
                                With Selection.Borders(xlEdgeRight)
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                                End With
                        Next
    End If
                    Next
                    Next
    End Sub

Discussions similaires

  1. Code VB6 à adapter pour VB4
    Par Whombat dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 10/03/2006, 10h50
  2. [débutant] Pb adaptation de code VBA
    Par delphineleclerc1 dans le forum Access
    Réponses: 9
    Dernier message: 28/02/2006, 12h58
  3. Réponses: 22
    Dernier message: 06/10/2005, 10h53
  4. [VBA Excel Word]Adapter un code Excel a Word
    Par Baxter67 dans le forum VBA Word
    Réponses: 4
    Dernier message: 08/08/2005, 23h43
  5. Adaptation d'un code TMemo vers TRichEdit : problème de ScrollBars
    Par Droïde Système7 dans le forum Composants VCL
    Réponses: 2
    Dernier message: 21/01/2005, 15h06

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