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 :

Allègement de code


Sujet :

Macros et VBA Excel

  1. #1
    Membre averti
    Inscrit en
    Décembre 2011
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2011
    Messages : 31
    Par défaut Allègement de code
    Bonjour Forum!!

    j'aurais besoin d'un petit coup de main pour nettoyer et allège certaine partie de code...et je sais, certains vont hurler....mais je sais juste bidouiller des bouts de code (et merci à tous ceux qui m'y ont aidé!!) ou les enregistrer avec l'enregistreur d'excel..Donc ils fonctionnent mais sont super lourd...alors si quelqu'un avait 2 minutes, j'en serais extrèmement reconnaissante!!!

    Un premier, particulièrement horrible je le conçois mais il permet de fusionner 5 lignes par cellules sur quasi 52 colonnes sauf la 7ème où il me faut absoluement mes 5 lignes.. (je sais la fusion de cellules c'est à éviter, mais j'ai pas trouver d'autres solutions dans mon cas...)

    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
    Sub Macro3()
    ' Création d'une nouvelle évaluation avec plusieurs lignes pour la case "classe pharmacothérapeutique" tout en gardant la protection de la feuille
    ' (=CommandButton2 création d'une nouvelle évaluation feuille "tableau")
     
        ActiveSheet.Unprotect
     
        ActiveCell.Range("A1:A6").Select
        Selection.EntireRow.Hidden = False
        Call Macro10
     
        ActiveCell.Offset(1, 0).Range("A1:A4").Select
        Selection.ClearContents
        ActiveCell.Offset(0, 25).Range("A1:E4").Select
        Selection.ClearContents
        ActiveCell.Offset(0, 6).Range("A1:C4").Select
        Selection.ClearContents
        ActiveCell.Offset(0, 5).Range("A1:D4").Select
        Selection.ClearContents
        ActiveCell.Offset(0, 5).Range("A1:A4").Select
        Selection.ClearContents
        ActiveCell.Offset(-1, -41).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        Selection.Copy
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        Selection.Copy
        ActiveCell.Offset(0, 2).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Application.CutCopyMode = False
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        Selection.Copy
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Application.CutCopyMode = False
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, 1).Range("A1:A5").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With
        Selection.Merge
        ActiveCell.Offset(0, -50).Range("A1:A5").Select
        ActiveCell.FormulaR1C1 = "=TODAY()"
         Selection.Merge
        ActiveCell.Offset(0, -1).Range("A1:A5").Select
           Call Macro6
     
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub
    Pour infos macro10:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Sub Macro10()
    'Copie des formules la ligne précédente
     
        ActiveCell.Rows("1:1").EntireRow.Select
        Selection.AutoFill Destination:=ActiveCell.Rows("1:6").EntireRow, Type:= _
            xlFillDefault
        ActiveCell.Rows("1:6").EntireRow.Select
     
     
     
    End Sub
    et macro 6
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Sub Macro6()
    ' permet l'attribution d'un nouveau numéro d'évaluation lors de la création d'une nouvelle ligne d'évaluation
    ' (=CommandButton2 création d'une nouvelle évaluation feuille "tableau")
     
           ActiveCell.FormulaR1C1 = _
            "=IF(ISBLANK(RC[1]),"""",IF(R[-1]C<>"""",R[-1]C+1,IF(R[-2]C<>"""",R[-2]C+1,IF(R[-3]C<>"""",R[-3]C+1,IF(R[-4]C<>"""",R[-4]C+1,R[-5]C+1)))))"
    End Sub
    Celui-ci serait également a simplifier. Il permet de masquer des lignes quand "NA" figure dans la colonne A de la ligne (peut être en faisant une boucle mais je n'y suis pas parvenu...) :

    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
    Sub macro7()
    'Permet de masquer les lignes de rapport inutiles
     
    Range("A1:Q120").Select
    Selection.EntireRow.Hidden = False
     
    If Range("a14") = "NA" Then
    Rows("14").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a15") = "NA" Then
    Rows("15").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a17") = "NA" Then
    Rows("17").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a18") = "NA" Then
    Rows("18").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a27") = "NA" Then
    Rows("27").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a28") = "NA" Then
    Rows("28").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a29") = "NA" Then
    Rows("29").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a32") = "NA" Then
    Rows("32").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a33") = "NA" Then
    Rows("33").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a43") = "NA" Then
    Rows("43").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a45") = "NA" Then
    Rows("45").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a46") = "NA" Then
    Rows("46").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("j62") = "NA" Then
    Rows("62").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a68") = "NA" Then
    Rows("68").Select
    Selection.EntireRow.Hidden = True
    End If
     
    If Range("a69") = "NA" Then
    Rows("69").Select
    Selection.EntireRow.Hidden = True
    End If
     
    End Sub
    Merci par avance!!!

  2. #2
    Nouveau candidat au Club
    Profil pro
    Chef de projet
    Inscrit en
    Juillet 2009
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chef de projet

    Informations forums :
    Inscription : Juillet 2009
    Messages : 2
    Par défaut Allègement de code
    Bonjour Forum et Bonjour Babou,
    Toute instruction ".select" suivi de "selection." à la ligne suivante peut s'alleger.
    Exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    ActiveCell.Range("A1:A6").Select
        Selection.EntireRow.Hidden = False
    peut s'écrire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ActiveCell.Range("A1:A6").EntireRow.Hidden = False
    OU

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    ActiveCell.Rows("1:1").EntireRow.Select
        Selection.AutoFill Destination:=ActiveCell.Rows("1:6").EntireRow, Type:= _
            xlFillDefault
    peut s'écrire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    ActiveCell.Rows("1:1").EntireRow.AutoFill Destination:=ActiveCell.Rows("1:6").EntireRow, Type:= _
            xlFillDefault
    Voilà.
    Bon courage

  3. #3
    Membre averti
    Inscrit en
    Décembre 2011
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2011
    Messages : 31
    Par défaut
    Désolé de ne répondre que maintenant, mais j'étais quelque peu indisponible ce temps-ci!!

    En tout cas Je te remercie beaucoup!! Et vais commencer par ça!!

    Mais y aurait-il une solution pour faire une boucle qui permettrait qu'excel recherche toutes les lignes dont la colonne A aurait comme valeur "NA" et les masque, plutôt que de citer les lignes à chaque fois?

  4. #4
    Membre Expert
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    673
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Conseil

    Informations forums :
    Inscription : Juin 2007
    Messages : 673
    Par défaut
    Bonjour,
    Voici une proposition de boucle pour masquer les lignes avec "NA" (le .EntireRows ne servait à rien):
    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
    Dim i As Integer
    Dim tabNumLignes(14) As Integer
     
        tabNumLignes(0) = 14
        tabNumLignes(1) = 15
        tabNumLignes(2) = 17
        tabNumLignes(3) = 18
        tabNumLignes(4) = 27
        tabNumLignes(5) = 28
        tabNumLignes(6) = 29
        tabNumLignes(7) = 32
        tabNumLignes(8) = 33
        tabNumLignes(9) = 43
        tabNumLignes(10) = 45
        tabNumLignes(11) = 46
        tabNumLignes(12) = 62
        tabNumLignes(13) = 68
        tabNumLignes(14) = 69
     
        For i = 0 To 14
            If Range("a" & tabNumLignes(i)) = "NA" Then
                Rows(tabNumLignes(i)).Hidden = True
            End If
        Next i

  5. #5
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    13 114
    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 : 13 114
    Billets dans le blog
    53
    Par défaut
    Bonjour,
    Une autre solution
    Considérant que la feuille se nomme maFeuille et que c'est la colonne A qui contient des cellules avec comme valeur possible NA
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Sub HiddenRow()
     Dim sht As Worksheet: Set sht = ThisWorkbook.Worksheets("maFeuille")
     Dim rng As Range
     For Each rng In sht.Range("A2:A" & sht.Range("A" & Rows.Count).End(xlUp).Row)
      If UCase(rng) = "NA" Then Rows(rng.Row).Hidden = True
     Next
    End Sub
    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

  6. #6
    Membre averti
    Inscrit en
    Décembre 2011
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2011
    Messages : 31
    Par défaut
    Merci beaucoup à corona et tedo01! Les deux solutions fonctionnent très bien.

    Maintenant( si je n'abuse pas trop de le demander...) par rapport au premier code, est ce qu'il est possible de faire une boucle du type de celle que vous m'avez passée précédemment mais pour les colonnes cette fois?? En fait il faudrait que les 4 cellules qui suivent la ligne sélectionnée soit fusionnées et ce de la colonne A jusqu'à la AZ sauf la G.
    Manuellement, ça me donne le code tout moche que j'ai mis dans mon premier post et j'aimerais vraiment alléger aussi...

    Merci beaucoup beaucoup!!!

  7. #7
    Membre Expert
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    673
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Conseil

    Informations forums :
    Inscription : Juin 2007
    Messages : 673
    Par défaut
    Bonjour,
    Voici une boucle pour les colonnes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Dim i As Integer
     
        For i = 0 To 5
            If i <> 6 Then
                ActiveCell.Offset(0, i).Range("A1:A5").Merge
            End If
        Next i

  8. #8
    Membre averti
    Inscrit en
    Décembre 2011
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2011
    Messages : 31
    Par défaut
    ça marche très bien!!! Merci beaucoup!!!!

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

Discussions similaires

  1. Allègement du code, passage par une class
    Par stolx_10 dans le forum C#
    Réponses: 2
    Dernier message: 28/03/2014, 16h03
  2. [XL-2003] allègement code ouverture d'un formulaire
    Par bosk1000 dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 14/12/2009, 23h56
  3. De la rapidité du code
    Par jfloviou dans le forum Contribuez
    Réponses: 233
    Dernier message: 29/05/2009, 02h17
  4. Explorateur de code C
    Par Zero dans le forum C
    Réponses: 14
    Dernier message: 06/06/2002, 09h41
  5. OmniORB : code sous Windows et Linux
    Par debug dans le forum CORBA
    Réponses: 2
    Dernier message: 30/04/2002, 17h45

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