XL 2013 [Résolu] VBA: code copier coller range plusieurs fois de suite trop lent

chacal33

XLDnaute Junior
Bonsoir à toutes et à tous,

avec l'aide du forum, j'ai récemment écrit une macro qui fonctionne bien mais qui se révèle beaucoup trop lente.

Si quelqu'un pouvait m'aider à optimiser ce code ou m'orienter vers la direction à prendre pour avoir un code plus rapide, ce serait idéal.
Le principe de la macro et de copier une range de cellule et de coller cette range plusieurs fois d'affilé

VB:
Sub APPROS3()

Application.ScreenUpdating = False

Sheets("PRETCD").Activate

Dim y As Long
Dim z As Long
Dim LastRPreTCD As Long
Dim LastCData As Long
LastRPreTCD = Sheets("PRETCD").Cells(Sheets("PRETCD").Rows.Count, "A").End(xlUp).Row
LastCData = Sheets("DATA").Cells(1, Sheets("DATA").Columns.Count).End(xlToLeft).Column

n = 2
For z = 2 To LastCData
For y = n To LastRPreTCD
Sheets("DATA").Cells(1, z).Copy Sheets("PRETCD").Cells(y, 12)
Next
n = n + Sheets("DANWARE").Range("M1")
Next

Application.ScreenUpdating = True

End Sub

Merci de votre retour.

Bonne soirée

Matthieu
 

pierrejean

XLDnaute Barbatruc
Bonjour Matthieu

A tester:
Code:
Sub APPROS3()

Application.ScreenUpdating = False

Sheets("PRETCD").Activate

Dim y As Long
Dim z As Long
Dim LastRPreTCD As Long
Dim LastCData As Long

LastRPreTCD = Sheets("PRETCD").Cells(Sheets("PRETCD").Rows.Count, "A").End(xlUp).Row
LastCData = Sheets("DATA").Cells(1, Sheets("DATA").Columns.Count).End(xlToLeft).Column
n = 2
ReDim tabres(2 To LastRPreTCD)
For z = 2 To LastCData
For y = n To LastRPreTCD
   tabres(y) = Sheets("DATA").Cells(1, z)
   'Sheets("DATA").Cells(1, z).Copy Sheets("PRETCD").Cells(y, 12)
Next
n = n + Sheets("DANWARE").Range("M1")
Next
Sheets("PRETCD").Cells(2, 12).Resize(UBound(tabres) - 1) = Application.Transpose(tabres)
Application.ScreenUpdating = True

End Sub
 

Statistiques des forums

Discussions
311 735
Messages
2 082 024
Membres
101 873
dernier inscrit
excellllll