Boucle loop

card

XLDnaute Nouveau
Bonjour à tous les lecteurs,

J'aimerais me débarrasser de cette loop.
Mais comment le code en l'état actuel loope sans s'arrêter:eek:

Le but serait que lorsque l'on clic sur le MonthView dans la liste box il m'affiche toutes les entrées de la date en question.

Le code fonctionne comment afficher tout d'un coup sans passer par :
If MsgBox("Suivant", vbYesNo + vbInformation) = vbNo Then Exit Do
sans compter que si on répond jamais VbNo bien entendu ça continue ....

Merci par avance pour vos réponses
Card

-------------------------------------------------------------------
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)


ListBox1.Clear
Application.Sheets("TeeOffTimes").Activate
[a2].Select

TXTDate.Text = MonthView1.Month & "/" & MonthView1.Day & "/" & MonthView1.Year



ListBox1.Clear
Dim findValue As String
Dim rngFind As Range

findValue = TXTDate.Text

Set rngFind = Range("A:J").Find(What:=findValue, After:=Range("B1"), LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)


If rngFind Is Nothing Then
' No Match
ListBox1.AddItem "RIEN"

Else

Do Until rngFind Is Nothing
ListBox1.AddItem rngFind & " " & rngFind.Offset(0, 1) & " " & rngFind.Offset(0, 2) & " " & rngFind.Offset(0, 3) & " " & rngFind.Offset(0, 4) & " " & rngFind.Offset(0, 5) & " " & rngFind.Offset(0, 6) & " " & rngFind.Offset(0, 7) & " " & rngFind.Offset(0, 8)

Set rngFind = Range("A:J").FindNext(rngFind)
If MsgBox("Suivant", vbYesNo + vbInformation) = vbNo Then Exit Do
Set rngFind = Range("A:J").FindNext(rngFind)
rngFind.Select
ActiveCell.EntireRow.Select

Loop

End If


End Sub
 

Roland_M

XLDnaute Barbatruc
Re : Boucle loop

bonjour
mais pourquoi mais tu Msgbox puisque tu boucle avec condition
Do Until rngFind Is Nothing ' < si cela est valable ça va sortir tout seul !
sinon c'est qu'il faut choir autre chose comme condition
Roland
 

roro69

XLDnaute Impliqué
Re : Boucle loop

Tiens essaye ce code:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Dim findValue As String
Dim rngFind As Range
Dim cel As Range
ListBox1.Clear
Application.Sheets("TeeOffTimes").Activate
[a2].Select
TXTDATE.Text = MonthView1.Month & "/" & MonthView1.Day & "/" & MonthView1.Year
ListBox1.Clear
findValue = TXTDATE.Text
Set rngFind = ActiveSheet.Range("A:J")
Set cel = rngFind.Cells.Find(CDate(findValue))
If cel Is Nothing Then
ListBox1.AddItem "RIEN"
Else
With ListBox1
.Clear
For Each cel In rngFind
If cel = findValue Then
.AddItem rngFind & " " & rngFind.Offset(0, 1) & " " & rngFind.Offset(0, 2) & " " & rngFind.Offset(0, 3) & " " & rngFind.Offset(0, 4) & " " & rngFind.Offset(0, 5) & " " & rngFind.Offset(0, 6) & " " & rngFind.Offset(0, 7) & " " & rngFind.Offset(0, 8)
With cel
.EntireRow.Select
Next cel
End With
End With

End If
Auterment mais un ptit bout de fichier si tu veut qu'on se rende compte plus facilement de ton problème.Allez bonne soirée
 

Roland_M

XLDnaute Barbatruc
Re : Boucle loop

re
si ça boucle à l'infini c'est que> Do Until rngFind Is Nothing < n'est valable !?
tu mets avant
-------------------------
If rngFind Is Nothing Then
' No Match
ListBox1.AddItem "RIEN"

Else
----------------
donc rngFind Is Nothing pour la boucle n'est valable c'est l'inverse !

Do Until (signifie sortie de la boucle Do Loop si > rngFind Is Nothing)
tout comme inversément
Do While (signifie boucle tant que > rngFind Is Nothing)
il faut connaître si (rngFind Is Nothing) est la condition pour sortir ou continuer tant que !?

Maintenant voir si le code que te propose roro69 te convient !? mais tu seras quoi avec Until et While, à savoir que While boucle avec Wend

Roland
 
Dernière édition:

Discussions similaires

Réponses
12
Affichages
682
Réponses
8
Affichages
588

Statistiques des forums

Discussions
313 344
Messages
2 097 337
Membres
106 916
dernier inscrit
Soltani mohamed