VBA Pilotage - Code d'erreur 6 et temps d'analyse trop long

Bonjour,

J'ai fait un vba pour suivre et piloter une activité de traitement des anomalies. Il fonctionne bien mais j'ai deux problèmes que j'arrive pas à les résoudre:

1. Le temps de calcul est trop long (voir parfois plus que 30 min pour effectuer une opération)

2. Un message d'erreur '6' "Dépassement de capacité'' s'affiche aussi.

Mon vba me permet de faire copier coller la première feuille ''stock DSN2" vers la feuille "A Traiter" en cliquant sur l'icône "Copier DSN2" sur la feuille "A Traiter".

Cette icone permet aussi de faire le triage et supprimer plusieurs lignes inutiles à travers le contenu des cellules de la colonne G. Les conditions pour supprimer une ligne sont déclarés dans le code VBA.

Comment je peux résoudre les deux problèmes (temps de traitement et l'erreur)?

Le fichier est en pièce jointe.

NB: Les données sont confidentielles c'est pour cela que je l'ai pas mis dans la première page

NB: J'ai 88000 lignes à analyser via le vba

Merci d'avance

Bonjour Ayoubranshu, bonjour le forum,

Peut-être comme ça :

Option Explicit

Sub Copier_DSN()
Dim S As Worksheet
Dim A As Worksheet
Dim DL As Long
Dim I As Long
Dim TV As Variant
Dim PL As Range

Application.ScreenUpdating = False
Application.EnableEvents = False
Set S = Worksheets("STOCK DSN 2")
Set A = Worksheets("A TRAITER")
A.Range("A1").CurrentRegion.Offset(1, 0).ClearContents
DL = S.Cells.SpecialCells(xlCellTypeLastCell).Row
S.Range("A2:V" & DL).Copy A.Range("A2")
Set PL = S.Range("A1")
TV = Range("G2:G" & DL)

' liste des lignes à supprimer'
For I = 2 To UBound(TV, 1)
    If TV(I, 1) = "383160348" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "379706344" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "378978498" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "378901946" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "352188601" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "352170161" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "339946469" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "332978485" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "323623603" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "323623603" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "315067942" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "130005481" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "64502636" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "399293380" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "400622452" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "403412463" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "408024719" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "409758448" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "410333223" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "412190977" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "414574053" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "414574152" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "414574525" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "414804476" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "419300678" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "419967468" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "420235137" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "422689208" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "428766976" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "431573013" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "433082476" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "439568700" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "434736617" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "435010202" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "439551110" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "439570417" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "442993358" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "448359117" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "451724082" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "478101959" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "480055664" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "485167647" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "491219457" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "501655880" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "501659056" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "504081233" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "552102121" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "552061335" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "542046065" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "538115684" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "517703369" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "509380614" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "508707262" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
Next I
PL.Delete
A.Rows("1:" & A.Range("H" & Rows.Count).End(xlUp).Row).Sort Key1:=A.Range("H1"), Order1:=xlAscending, Header:=xlYes
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

Bonjour ayoubranshu le forum

Bonjour Robert

il faut passer par des tableaux tout simplement et tes 88000 lignes vont être traitées en 2 secondes max

mais avec un fichier Archi Vide cela va beaucoup plus vite

a+

Papou

Bonjour,

Merci pour ton retour rapide

J'ai testé le code que tu as mis mais le message d'erreur de dépassement de capacité s'affiche encore

Bonjour Ayoubranshu, bonjour le forum,

Peut-être comme ça :

Option Explicit

Sub Copier_DSN()
Dim S As Worksheet
Dim A As Worksheet
Dim DL As Long
Dim I As Long
Dim TV As Variant
Dim PL As Range

Application.ScreenUpdating = False
Application.EnableEvents = False
Set S = Worksheets("STOCK DSN 2")
Set A = Worksheets("A TRAITER")
A.Range("A1").CurrentRegion.Offset(1, 0).ClearContents
DL = S.Cells.SpecialCells(xlCellTypeLastCell).Row
S.Range("A2:V" & DL).Copy A.Range("A2")
Set PL = S.Range("A1")
TV = Range("G2:G" & DL)

' liste des lignes à supprimer'
For I = 2 To UBound(TV, 1)
    If TV(I, 1) = "383160348" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "379706344" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "378978498" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "378901946" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "352188601" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "352170161" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "339946469" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "332978485" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "323623603" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "323623603" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "315067942" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "130005481" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "64502636" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "399293380" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "400622452" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "403412463" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "408024719" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "409758448" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "410333223" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "412190977" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "414574053" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "414574152" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "414574525" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "414804476" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "419300678" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "419967468" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "420235137" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "422689208" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "428766976" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "431573013" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "433082476" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "439568700" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "434736617" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "435010202" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "439551110" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "439570417" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "442993358" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "448359117" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "451724082" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "478101959" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "480055664" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "485167647" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "491219457" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "501655880" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "501659056" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "504081233" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "552102121" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "552061335" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "542046065" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "538115684" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "517703369" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "509380614" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
    If TV(I, 1) = "508707262" Then Set PL = IIf(PL.Cells.Count = 1, S.Rows(I), Application.Union(PL, S.Rows(I)))
Next I
PL.Delete
A.Rows("1:" & A.Range("H" & Rows.Count).End(xlUp).Row).Sort Key1:=A.Range("H1"), Order1:=xlAscending, Header:=xlYes
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

Bonjour

j'ai pas compris est ce que tu peux m'expliquer stp et merci d'avance

Bonjour ayoubranshu le forum

Bonjour Robert

il faut passer par des tableaux tout simplement et tes 88000 lignes vont être traitées en 2 secondes max

mais avec un fichier Archi Vide cela va beaucoup plus vite

a+

Papou

Bonjour ayoubranshu le forum

tu n'as pas compris???

Explications:

j'ai dit Bonjour Robert car ThauThème est une connaissance de longue date

il faut passer par des tableaux tout simplement et tes 88000 lignes vont être traitées en 2 secondes max

Bah c'est très simple ce qui est long dans ta macro c'est les multiples actions sur la feuille de destination, donc en travaillant avec des tableaux on travaille en mémoire, et le boulot est fait environ 100 fois plus vite.

Maintenant tu as donné un fichier vide alors pas moyen de tester, mais pour ta confidentialité, tu repasseras, car tu prends ton fichier tu vides toutes les colonnes sauf la colonnes G et tu passes ton fichier et là je ne pense pas que tes suites de chiffres soit confidentielles "383160348" etc etc

Si tu veux je te le ferai, mais tu rajoutes juste une feuille Exclusion, dans laquelle tu mets dans la colonne A toutes les références à exclures de tes données, tu passes ensuite ton fichier avec la colonne G remplies et tes 88000 lignes et tu auras ce que tu souhaites, du moins je le pense

a+

Papou

Re bonjour ayoubranshu le forum

Voilà avec le fichier que tu n'as pas su faire !!!!

a+

Papou

3ayoubranshu-v1.zip (753.28 Ko)

Bonjour,

merci bcp pour votre aide et votre réponse et je m'excuse pour ma réponse tardive

Re ayoubranshu le forum

oui tu as vu moins de 1 seconde pour traiter tes 95000 lignes en gérant les exclusions

a+

Papou

Rechercher des sujets similaires à "vba pilotage code erreur temps analyse trop long"