[VBA] Boucle infinie - HELP!!!
Résolu
Ancelot
-
Ancelot -
Ancelot -
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,
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,
A voir également:
- [VBA] Boucle infinie - HELP!!!
- Excel compter cellule couleur sans vba - Guide
- Code gta 5 ps3 vie infinie - Guide
- Vba attendre 1 seconde ✓ - Forum VB / VBA
- Télé samsung s'éteint et se rallume en boucle - Forum Téléviseurs
- Find vba - Astuces et Solutions
1 réponse
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+
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+
Je tacheré d eviter les sheet select dorénavant..