[VBA] Boucle infinie - HELP!!!
Résolu/Fermé
A voir également:
- [VBA] Boucle infinie - HELP!!!
- Excel compter cellule couleur sans vba - Guide
- Vba attendre 1 seconde ✓ - Forum VB / VBA
- Mkdir vba ✓ - Forum VB / VBA
- Xiaomi s'éteint tout seul et se rallume en boucle - Forum Xiaomi
- Boucle cmd - Forum Programmation
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
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+
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+
7 mai 2009 à 09:39
Je tacheré d eviter les sheet select dorénavant..