Vba boucle for next

asterrax Messages postés 13 Statut Membre -  
asterrax Messages postés 13 Statut Membre -
Bonjour,

J'ai un code simple qui a une vitesse d'exécution très lente. Comment l'améliorer? Le but est de copier coller une ligne sur deux sur une autre destination.

Sub diviseL()
Dim NbLigne As String, I As String

NbLigne = Cells(5, 3).End(xlDown).Row - 4
NbLigne = NbLigne / 2
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For I = 1 To NbLigne
Range(Cells(4 + I, 6), Cells(4 + I, 8)).Value = Range(Cells(4 + 2 * I, 2), Cells(4 + 2 * I, 4)).Value
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Next I
End Sub

Merci!

2 réponses

  1. Mytå Messages postés 4246 Date d'inscription   Statut Contributeur Dernière intervention   957
     
    Salut le forum

    Déplace les lignes
    Application.Calculation = xlCalculationAutomatic 
    Application.ScreenUpdating = True 
    

    Après ton Next I

    Mytå
    0
  2. asterrax Messages postés 13 Statut Membre
     
    merci! vraiment bête mon erreur....la fatigue surement....
    j'ai lancé mon application avec ça finalement

    Sub ligne()
    Dim A, B
    A = 0
    B = 0
    Application.Calculation = xlCalculationManual
    While Cells(A + 5, 2) <> ""
    Cells(B + 5, 6) = Cells(A + 5, 2)
    Cells(B + 5, 7) = Cells(A + 5, 3)
    Cells(B + 5, 8) = Cells(A + 5, 4)
    A = A + 2
    B = B + 1
    Wend
    Application.Calculation = xlCalculationAutomatic

    End Sub

    quelle méthode est la plus rapide ou efficace dans un code plus complet? for next ou while wend ou autre?
    0