[VBA] Boucle infinie - HELP!!!

Résolu/Fermé
Ancelot - 5 mai 2009 à 16:50
 Ancelot - 7 mai 2009 à 09:39
Bonjour,

Je vous écris dans un état de désespoir !! ça fait deux heures que je suis en train de déboguer la macro que j'ai créé sans succès. En l'exécutant, le programme tourne en boucle infinie et plante excel.

Peut être que quelqu'un en jetant un coup d'oeil comprendrait pourquoi? Voici mon code

Sub Gap_Identifier()
'
' Gap_Identifier Macro
'
Dim l As Long
Dim m As Long
Dim n As Long
Dim x As Long
Dim y As Long
Dim z As Long
Dim NomRessource As String
Dim WkRessource As String
Dim WkTopic As String

Sheets("SAY").Select

For l = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
WkRessource = Range("C" & l).Value
NomRessource = Range("A" & l).Value
Sheets("LISTEN").Select
z = 0
For m = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
If Range("A" & m).Value = WkRessource Then z = m
Next m
While Range("A" & z).Value = WkRessource
WkTopic = Range("D" & z)
z = z + 1
Sheets("ASK").Select
y = 0
For n = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
If Range("A" & n).Value = WkRessource And Range("E" & n).Value = WkTopic Then y = n
Next n
Sheets("ANSWER").Select
x = 1
If y = 0 Then
Range("A" & x).Value = NomRessource
Range("E" & x).Value = WkTopic
End If

Wend

Next l

End Sub

J'ai bien verifié que mes conditions de sortie soient respectés. Merci énormément pour votre aide,

1 réponse

pilas31 Messages postés 1825 Date d'inscription vendredi 5 septembre 2008 Statut Contributeur Dernière intervention 24 avril 2020 644
5 mai 2009 à 19:10
bonjour,

Il me semble que le problème vient des select successifs qui font que l'on est pas positionnés dans la même feuille en entrée et en sortie de boucle. De plus si z est nul il y a une erreur sur le range. Donc je propose d'essayer les modifications suivantes (en gras) :

Sub Gap_Identifier()
'
' Gap_Identifier Macro
'
Dim l As Long
Dim m As Long
Dim n As Long
Dim x As Long
Dim y As Long
Dim z As Long
Dim NomRessource As String
Dim WkRessource As String
Dim WkTopic As String

Sheets("SAY").Select
For l = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
WkRessource = Range("C" & l).Value
NomRessource = Range("A" & l).Value
Sheets("LISTEN").Select
z = 0
For m = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
If Range("A" & m).Value = WkRessource Then z = m
Next m
If z <> 0 Then
While Range("A" & z).Value = WkRessource
WkTopic = Range("D" & z)
z = z + 1
Sheets("ASK").Select
y = 0
For n = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
If Range("A" & n).Value = WkRessource And Range("E" & n).Value = WkTopic Then y = n
Next n
Sheets("ANSWER").Select
x = 1
If y = 0 Then
Range("A" & x).Value = NomRessource
Range("E" & x).Value = WkTopic
End If
Sheets("LISTEN").Select
Wend
End If
Sheets("SAY").Select

Next l
End Sub

Remarque : Normalement il vaut mieux éviter les select.

A+
0
Supeeeerrr ca marche!!! merci beaucoup!!!!!!
Je tacheré d eviter les sheet select dorénavant..
0