Optimiser code Excel vb (out of memory error)

yoyoxls Messages postés 2 Date d'inscription samedi 1 août 2009 Statut Membre Dernière intervention 4 août 2009 - 1 août 2009 à 01:51
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 - 4 août 2009 à 13:49
Bonjour,

J'ai une une Out of Memory Runtime Error... dans excel 2002.
Merci de m'aider a optimiser ce code pour résoudre le problème?

NbLignes = 501
For i = 8 To NbLignes
trouv = ""
indice = ""
If IsNumeric(Range("AA" & i).Value) Then
If Range("AA" & i).Value > 0 Then
Range("AA" & i).Hyperlinks.Add Anchor:=Range("AA" & i), Address=Range("AA" & i).Value
End If
End If
If Application.CountIf(Worksheets("PendingMonitor").R ange("C7:C3500"), Range("AA" & i).Value) > 0 Then
indice = Application.Match(Range("AA" & i).Value, Worksheets("PendingMonitor").Range("C7:C3500"), 0)
trouv = Application.Index(Worksheets("PendingMonitor").Ran ge("C7:C3500"), indice)
End If
If trouv "" Or indice "" Then
Range("AE" & i).Value = Range("B" & i).Value
Range("AF" & i).Value = Range("C" & i).Value
Range("AG" & i).Value = Range("F" & i).Value
Range("AH" & i).Value = Range("H" & i).Value
Range("AI" & i).Value = Range("G" & i).Value
Range("AJ" & i).Value = Range("I" & i).Value
Range("AK" & i).Value = Range("J" & i).Value
Range("AL" & i).Value = Range("L" & i).Value
Range("AM" & i).Value = Range("M" & i).Value
Range("AN" & i).Value = Range("N" & i).Value
Range("AO" & i).Value = Range("O" & i).Value
Range("AP" & i).Value = Range("P" & i).Value
Range("AQ" & i).Value = Range("R" & i).Value
Else
Range("AE" & i).Value = Worksheets("PendingMonitor").Range("E" & indice).Value
Range("AF" & i).Value = Worksheets("PendingMonitor").Range("F" & indice).Value
Range("AG" & i).Value = Worksheets("PendingMonitor").Range("G" & indice).Value
Range("AH" & i).Value = Worksheets("PendingMonitor").Range("M" & indice).Value
Range("AI" & i).Value = Worksheets("PendingMonitor").Range("H" & indice).Value
Range("AJ" & i).Value = Worksheets("PendingMonitor").Range("J" & indice).Value
Range("AK" & i).Value = Worksheets("PendingMonitor").Range("I" & indice).Value
Range("AL" & i).Value = Worksheets("PendingMonitor").Range("AP" & indice).Value
Range("AM" & i).Value = Worksheets("PendingMonitor").Range("U" & indice).Value
Range("AN" & i).Value = Worksheets("PendingMonitor").Range("AN" & indice).Value
Range("AO" & i).Value = Worksheets("PendingMonitor").Range("D" & indice).Value
Range("AP" & i).Value = Worksheets("PendingMonitor").Range("K" & indice).Value
Range("AQ" & i).Value = Worksheets("PendingMonitor").Range("N" & indice).Value
End If
Next i
End Sub

3 réponses

NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
3 août 2009 à 15:28
Bonjour,

Qu'est sensé faire ce code ?

0
yoyoxls Messages postés 2 Date d'inscription samedi 1 août 2009 Statut Membre Dernière intervention 4 août 2009
4 août 2009 à 10:59
Bonjour,

J'utilise un fichier excel pour faire du monitoring d'incidents.
On avait commencé par gérer les incidents manuellement dans les colonnes B:R du feuillet actif, puis on a utilisé un soft relié à une base de données dont on récupère les données dans le feuillet pendingmonitor.

Le code VBA est censé:
1 - Créer un hyperlien sur le numéro d'incident vers la base de données (cela fonctionne)
2 - Suite à une recherche, si le numéro d'incident est trouvé dans le feuillet colonne C du pendingmonitor, il va copier les données de la ligne correspondante sinon il copie les données manuelles des colonnes B:R. (Cela fonctionne en test et jusqu'à 64 lignes avant de générer l'erreur out of memory)
Je n'utilise pas de formule car je souhaite copier les valeurs.
La macro doit tourner 2 à 3 fois par jour pour rafraichir les données.
0
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
4 août 2009 à 13:49
Bonjour,

Je ne vois pas d'où sa peut venir, mais quelques conseil :
- à la place de
Worksheets("PendingMonitor")
Assigne un nom à la feuille (dans l'explorateur VBA), et utilises la à la place de Worksheets("PendingMonitor"), cela accélèrera le code.
- à la place de
Range("AE" & i)
Préfère utiliser Cells, plus rapide mais pas de multiselection.

Je ne sais pas si ça solutionnera ton problème, mais ça limitera la recherche d'objet.

0
Rejoignez-nous