XL 2010 Optimisation boucle vba

Profane

XLDnaute Occasionnel
Bonjour à tous,
voila mon soucis, j'ai une macro vba qui fonctionne tres bien...MAIS
elle est trop lente sur un fichier de 55000 lignes,
j'aimerai l'optimiser (actuellement = 15mn de traitement.....) , je pense que l'utilisation de tableau (Lbound,Ubound) m'aiderait mais je ne connais pas trop l'utilisation
d'avance merci pour votre aide
voici la macro :

Sub SuppEspace()
k = Timer
' Arret du calcul automatique
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim L As Integer
Dim WS1
Dim i As Long
'on declare les variables
Set WS1 = Sheets("Export")


For L = 106 To 107 ' on scrute 2 colonnes

If WS1.Cells(1, L) = "tintin v2" And WS1.Cells(1, L + 1) = "Milou v2" Then
With WS1
For i = WS1.Range("A65536").End(xlUp).Row To 2 Step -1
If WS1.Range("A" & i).Value <> "" Then
WS1.Range("DB" & i) = Application.Trim(Range("AO" & i))
WS1.Range("DC" & i) = Application.Trim(Range("BM" & i))
WS1.Range("DD" & i) = Application.Trim(Range("AC" & i))

End If
Next i
End With
End If

Next L

'Calcul automatique
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
MsgBox ("Durée : " & Timer - k)
End Sub
 

mapomme

XLDnaute Barbatruc
Supporter XLD
Bonsoir Profane,

Un fichier joint eût été plus qu’apprécié :cool:.

Voir la macro Supprespace() dans le fichier joint.

Rem : les 15 minutes d’exécution de votre macro initiale me semblent étrangement élevées. Si on fait tourner votre macro sur les données du fichier joint, le temps d'exécution est inférieur à 15 secondes.
 

Pièces jointes

  • Profane- Supprespace- v1.xlsm
    21.6 KB · Affichages: 44
Dernière édition:

Statistiques des forums

Discussions
311 721
Messages
2 081 928
Membres
101 842
dernier inscrit
seb0390