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 :

Macro copier coller très lente


Sujet :

Macros et VBA Excel

  1. #1
    Candidat au Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Décembre 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chargé d'affaire
    Secteur : Transports

    Informations forums :
    Inscription : Décembre 2015
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Macro copier coller très lente
    Bonjour je m'adresse à vous les spécialiste ou amateur du VBA
    j'ai un petit problème, j'ai un fichier excel qui contient plusieur feuilles je voudrai copier une plage des cellules (a7:a20) et sauter 34 lignes puis copier la plage (a41:a54) etc.... jusu'au la ligne 17000.
    j'ai reussi à faire une macro dont les détails ci-après, cette macro est tres lente dans son execution puisque je n'ai pas pu copier la plage, j'ai copier ligne par ligne
    c'est très long ....
    merci pour votre aide
    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
    Public Sub m1() 
    h = 2 
    For I = 7 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m2() 
    h = 3 
    For I = 8 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m3() 
    h = 4 
    For I = 9 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m4() 
    h = 5 
    For I = 10 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m5() 
    h = 6 
    For I = 11 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m6() 
    h = 7 
    For I = 12 To 1700 Step 34 
    Sheets("bltar").Range("D" & I).copy 
    Sheets("valtar").Range("B" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m7() 
    h = 8 
    For I = 13 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
     
    Public Sub m8() 
    h = 9 
    For I = 14 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
     
     
    Public Sub m9() 
    h = 10 
    For I = 15 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m10() 
    h = 11 
    For I = 16 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m11() 
    h = 12 
    For I = 17 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m12() 
    h = 13 
    For I = 18 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
     
    Public Sub m13() 
    h = 14 
    For I = 19 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
    Public Sub m14() 
    h = 15 
    For I = 20 To 1700 Step 34 
    Sheets("bltar").Range("A" & I).copy 
    Sheets("valtar").Range("D" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("b" & I).copy 
    Sheets("valtar").Range("G" & h).PasteSpecial Paste:=xlValues 
    Sheets("bltar").Range("E" & I).copy 
    Sheets("valtar").Range("H" & h).PasteSpecial Paste:=xlValues 
    Application.CutCopyMode = False 
    h = h + 14 
    Next 
    End Sub 
     
    Sub mymacros() 
    m1 
    m2 
    m3 
    m4 
    m5 
    m6 
    m7 
    m8 
    m9 
    m10 
    m11 
    m12 
    m13 
    m14 
    End Sub

  2. #2
    Membre averti
    Homme Profil pro
    Inscrit en
    Octobre 2012
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2012
    Messages : 199
    Points : 319
    Points
    319
    Par défaut
    Bonjour,

    Une piste à étudier.

    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
     
    Sub test()
     
    Dim monAppli As String
    Dim fichier_appli As Workbook, feuille_source As Worksheet, feuille_cible As Worksheet
    Dim cpt_l As Integer, cpt_c As Integer, ligneCopie As Integer, colonneCopie As Integer
     
    monAppli = ActiveWorkbook.Name
     
    Set fichier_appli = Workbooks(monAppli)
    Set feuille_source = fichier_appli.Worksheets("bltar")
    Set feuille_cible = fichier_appli.Worksheets("valtar")
     
    ligneCopie = 2
     
    For cpt_l = 7 To 1700 Step 34
        feuille_cible.Cells(ligneCopie, 4) = feuille_source.Cells(cpt_l, 1)
        feuille_cible.Cells(ligneCopie, 7) = feuille_source.Cells(cpt_l, 2)
        feuille_cible.Cells(ligneCopie, 8) = feuille_source.Cells(cpt_l, 5)
     
        ligneCopie = ligneCopie + 14
     
    Next cpt_l
     
    End Sub
     
    Cordialement,

  3. #3
    Membre expérimenté
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Septembre 2013
    Messages
    783
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Septembre 2013
    Messages : 783
    Points : 1 562
    Points
    1 562
    Par défaut
    Bonjour,

    copier une plage des cellules (a7:a20) et sauter 34 lignes puis copier la plage (a41:a54)
    => est-ce-qu'il y a un différenciateur dans vos données vous permettant de sélectionner les lignes à copier, et qui permettraient de faire cela en peu de lignes de code par un filtre?
    => Vous pourriez donner un exemple de la feuille source?

  4. #4
    Candidat au Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Décembre 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chargé d'affaire
    Secteur : Transports

    Informations forums :
    Inscription : Décembre 2015
    Messages : 2
    Points : 2
    Points
    2
    Par défaut
    Merci "goldstar" pour ta réponse, mais la macro que tu m'as proposée ne copie que la première ligne de chaque plage cad a7 puis a41 etc ...donc si j'ai bien compris je dois recopier cette macro 14 fois en changeant juste le numero de ligne .
    je cherche à faire copier la plage a7:a20 et faire une boucle en sautant 34 lignes .


    cdl
    Rached
    Fichiers attachés Fichiers attachés

  5. #5
    Membre expérimenté
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Septembre 2013
    Messages
    783
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Septembre 2013
    Messages : 783
    Points : 1 562
    Points
    1 562
    Par défaut
    Bonjour,

    Brut de fonderie, c'est un peu difficile de faire quelque chose de propre et rapide avec ce type de structure données. Ce n'est pas une critique, mais un fort appel à mieux structurer vos données d'entrée.

    Ce que vous pourriez faire: rajouter un champ (basé sur une fonction excel par exemple: Counta, Countblank, ....) qui vous permettrait d'automatiser le transfert en une passe (il suffirait de filtrer vos données sur ce critère)

    Voir exemple (sans filtre) en utilisant juste des propriétés d'affichage SpecialCells(xlCellTypeVisible): je n'affiche que les lignes qui contiennent des valeurs et je les copie en une passe

    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
    Sub Test_Extract()
     
        Dim InpRng As Range
     
     'On prend d'abord le range total
        Set InpRng = ThisWorkbook.Worksheets("bltar").UsedRange
        Debug.Print InpRng.AddressLocal, InpRng.Cells.Count
     
    'On extrait uniquement ce qui n'est pas vide (on aurait pu le faire en une passe dans le Set précédent)
        Set InpRng = InpRng.SpecialCells(xlCellTypeConstants)
        Debug.Print InpRng.AddressLocal, InpRng.Cells.Count
     
    'Je masque toutes les lignes, sauf celles pour lesquelles il y a des valeurs (constantes) 
        ActiveSheet.Rows.Hidden = True
        InpRng.Rows.Hidden = False
     
    'et hop: je ne copie que ce qui est affiché!
        Cells.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("valtar").Range("A10")
        ActiveSheet.Rows.Hidden = False
     
    End Sub

Discussions similaires

  1. Macro copier-coller
    Par pucelo dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 21/10/2008, 19h49
  2. [A-00] macro copier coller
    Par nadege46 dans le forum IHM
    Réponses: 1
    Dernier message: 14/10/2008, 21h41
  3. Macro copier/coller avec tri
    Par Lechette dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 20/03/2008, 12h44
  4. Macro copier coller première cellule vide
    Par jul85 dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 24/02/2008, 17h06
  5. Macro copier/coller colonne- insérer nouvelle colonne
    Par rembliec dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 15/11/2007, 16h32

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