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 :

Ecrire en plus court le code


Sujet :

Macros et VBA Excel

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2012
    Messages : 17
    Points : 5
    Points
    5
    Par défaut Ecrire en plus court le code
    Bonjour, je m'aventure sur le code vba sous excel j'aimerais que vous me disiez si il y a moyen de faire plus court.

    Voici le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    Sub Actualisation1()
    Application.ScreenUpdating = True
     
    ' Macro2 Macro
    ' Macro enregistrée le 29/02/2012 par Full Name
    '
     
    ' Début Macro Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a5:b6").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b3:c4").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Janvier Reunion 1
     
    Range("b9").Select
    Sheets("Test Planning CDC").Select
    Range("a8:b10").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b22:c24").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Fevrier Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a13:b15").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b41:c43").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Mars Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a17:b19").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b60:c62").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Avril Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a21:b23").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b79:c81").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Mai Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a25:b27").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b99:c101").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Juin Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a29:b31").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b119:c121").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Juillet Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a37:b39").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b139:c141").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Septembre Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a41:b43").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b159:c161").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Octobre Reunion 1
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a45:b47").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b181:c183").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    ' Décembre Reunion 1
     
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("a49:b51").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b203:c205").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("a1").Select
    '
    '
    '
    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
    'Début macro Réunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e5:f6").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b11:c13").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Janvier Reunion 2
     
    Range("b9").Select
    Sheets("Test Planning CDC").Select
    Range("e8:f10").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b32:c34").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Fevrier Reunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e13:f15").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b50:c52").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Mars Reunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e17:f19").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b69:c71").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Avril Reunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e21:f23").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b88:c90").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Mai Reunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e25:f27").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b107:c109").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Juin Reunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e29:f31").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b129:c131").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Juillet Reunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e37:f39").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b149:c151").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Septembre Reunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e41:f43").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b170:c172").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    'Octobre Reunion 2
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e45:f47").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b190:c192").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    ' Décembre Reunion 2
     
     
    Range("b3").Select
    Sheets("Test Planning CDC").Select
    Range("e49:f51").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("b212:c214").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("a1").Select
    MsgBox "L'actualisation s'est réalisée"
    '
    '
     
     
    End Sub
    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
     
    Sub Actualisation2()
    Application.ScreenUpdating = True
    ' Actualisation2 Macro
    ' Copie les sponsors
    '
    Range("a1").Select
    Sheets("Test Planning CDC").Select
    Range("c5:c6").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e3:e4").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c8:c10").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e22:e24").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c13:c15").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e41:e43").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c17:c19").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e60:e62").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c21:c23").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e79:e81").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c25:c27").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e99:e101").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c29:c31").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e119:e121").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c37:c39").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e139:e141").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c41:c43").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e159:e161").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c45:c47").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e181:e183").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("c49:c51").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e203:e205").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("g5:g6").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e11:e12").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("g8:g10").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e32:e34").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("g13:g15").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e50:e52").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("g17:g19").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e69:e71").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
     
    '
     
    Sheets("Test Planning CDC").Select
    Range("g21:g23").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e88:e90").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    '
     
    Sheets("Test Planning CDC").Select
    Range("g25:g27").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e107:e109").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    '
     
    Sheets("Test Planning CDC").Select
    Range("g29:g31").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e129:e131").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    '
     
    Sheets("Test Planning CDC").Select
    Range("g37:g39").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e149:e151").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    '
     
    Sheets("Test Planning CDC").Select
    Range("g41:g43").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e170:e172").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    '
     
    Sheets("Test Planning CDC").Select
    Range("g45:g47").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e190:e192").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    '
     
    Sheets("Test Planning CDC").Select
    Range("g49:g51").Select
    Selection.Copy
    Sheets("Test Plannification Travaux").Select
    Range("e212:e214").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("a1").Select
    MsgBox "Les sponsors se sont copiés"
     
    '
    End Sub

  2. #2
    Membre expert
    Homme Profil pro
    Retraité
    Inscrit en
    Avril 2011
    Messages
    1 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 858
    Points : 3 974
    Points
    3 974
    Par défaut
    Bonjour,

    Voici un exemple de simplification appliquée à la procédure Actualisation1.
    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
    Option Explicit
    Sub Actualisation1()
    ' Macro2 Macro
    ' Macro enregistrée le 29/02/2012 par Full Name
    ' Début Macro Reunion 1
    Dim Ws1 As Worksheet
    Dim Ws2 As Worksheet
        Set Ws1 = Worksheets("Test Planning CDC")
        Set Ws2 = Worksheets("Test Plannification Travaux")
        Application.ScreenUpdating = False
        With Ws1
            .Range("a5:b6").Copy Destination:=Ws2.Range("b3")
            'Janvier Reunion 1
            .Range("a8:b10").Copy Destination:=Ws2.Range("b22")
            'Fevrier Reunion 1
            .Range("a13:b15").Copy Destination:=Ws2.Range("b41")
            'Mars Reunion 1
            .Range("a17:b19").Copy Destination:=Ws2.Range("b60")
            'Avril Reunion 1
            .Range("a21:b23").Copy Destination:=Ws2.Range("b79")
            'Mai Reunion 1
            .Range("a25:b27").Copy Destination:=Ws2.Range("b99")
            'Juin Reunion 1
            .Range("a29:b31").Copy Destination:=Ws2.Range("b119")
            'Juillet Reunion 1
            .Range("a37:b39").Copy Destination:=Ws2.Range("b139")
            'Septembre Reunion 1
            .Range("a41:b43").Copy Destination:=Ws2.Range("b159")
            'Octobre Reunion 1
            .Range("a45:b47").Copy Destination:=Ws2.Range("b181")
            ' Décembre Reunion 1
            .Range("a49:b51").Copy Destination:=Ws2.Range("b203")
            Application.CutCopyMode = False
            Application.ScreenUpdating = True
            .Select
            .Range("a1").Select
        End With
        Set Ws1 = Nothing
        Set Ws2 = Nothing
    End Sub
    Tu pourras facilement le reproduire sur les autres procédures.

    Cordialement.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2012
    Messages : 17
    Points : 5
    Points
    5
    Par défaut
    Merci beaucoup, ton exemple est très clair.

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

Discussions similaires

  1. Avoir du code plus court.
    Par defacta dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 28/04/2010, 08h14
  2. Calcul de plus court chemin dans un graphe
    Par Elmilouse dans le forum Prolog
    Réponses: 6
    Dernier message: 21/03/2010, 20h26
  3. Ecrire un code en plus court
    Par NEC14 dans le forum Macros et VBA Excel
    Réponses: 18
    Dernier message: 18/10/2007, 09h33
  4. algorithme de Ford (recherche chemin le plus court)
    Par abstraite dans le forum Algorithmes et structures de données
    Réponses: 2
    Dernier message: 19/05/2005, 10h39
  5. Réponses: 2
    Dernier message: 21/03/2004, 18h57

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