boucles for next

David59

XLDnaute Junior
Bonjour forum

Mon problème je voudrais voir que quelque ligne d'une liste
J’ai donc créé un userform
Code:
Private Sub CommandButton1_Click()
Dim i As Integer
For i = 1 To 70

If Sheets("feuil1").Range("c" & i) = "oui" Then
TextBox1 = Sheets("feuil1").Range("a" & i)
TextBox2 = Sheets("feuil1").Range("b" & i)
 CommandButton1.Caption = "suivant"

End If
 Next i
 CommandButton1.Caption = "Fini"
End Sub
Avec cette formule j'ai la dernière ligne
J’aimerais qu'il s'arrête des la 1er info trouvé et ensuite en recliquant sur le bouton CommandButton1 continuer la recherche
Quand je mets un Msgbox après CommandButton1.Caption = "suivant"
Ça fonctionne
Peut-on faire sans le mgsbox

Merci d'avance
David @+
 

Pièces jointes

  • Classeur1.xlsm
    21.9 KB · Affichages: 54
  • Classeur1.xlsm
    21.9 KB · Affichages: 57
  • Classeur1.xlsm
    21.9 KB · Affichages: 57

soenda

XLDnaute Accro
Re : boucles for next

Bonjour le fil, David59

L'utilisation d'une variable Static devrait résoudre le problème.
Par exemple :
Code:
Private Sub CommandButton1_Click()
    [B][COLOR=blue]Static[/COLOR][/B] L As Integer
 
    With Feuil1
 
        Do While .[C1].Offset(L).Value <> "oui" And L <= 69
            L = L + 1
        Loop
 
        If L = 70 Then
            CommandButton1.Caption = "Fini"
        Else
            TextBox1 = .[A1].Offset(L).Value
            TextBox2 = .[B1].Offset(L).Value
            CommandButton1.Caption = "Suivant"
            L = L + 1
        End If
 
    End With
End Sub
L qui est une variable Static, conserve sa valeur entre chaque clic sur CommandButton1
La première boucle incrémente L, si L < 70 et tant que la cellule <> "oui"

A plus
 

Discussions similaires

Statistiques des forums

Discussions
312 538
Messages
2 089 403
Membres
104 160
dernier inscrit
dqldq