Boucle For sur Colonne

raclette

XLDnaute Nouveau
Bonjour à tous,

je cherche un peu d'aide sur une boucle For qui me retourne un problème que je n'arrive pas à résoudre.

Code:
For I = A To Z

    If ComboBox1.Value = "416" Then
       If ComboBox2.Value = Feuil5.Range(I & "2") Then
          
         TextBox1.Value = Feuil5.Range(I & "3").Value
         TextBox2.Value = Feuil5.Range(I & "4").Value
         TextBox3.Value = Feuil5.Range(I & "5").Value
         TextBox4.Value = Feuil5.Range(I & "6").Value
         TextBox5.Value = Feuil5.Range(I & "7").Value
         TextBox6.Value = Feuil5.Range(I & "8").Value
         TextBox7.Value = Feuil5.Range(I & "9").Value
         TextBox8.Value = Feuil5.Range(I & "10").Value
         
       Else
    
        TextBox1.Value = ""
        TextBox2.Value = ""
        TextBox3.Value = ""
        TextBox4.Value = ""
        TextBox5.Value = ""
        TextBox6.Value = ""
        TextBox7.Value = ""
        TextBox8.Value = ""
      End If
      Else
       End If
Next I

Quelqu'un sait il me donner une explication ou une piste ?
 

Robert

XLDnaute Barbatruc
Repose en paix
Re : Boucle For sur Colonne

Bonjour Raclette, bonjour le forum,

Difficile de t'aider sans données concrètes... Peut-être comme ça si la valeur est numérique :
Code:
If ComboBox2.Value = CStr(Sheets("Feuil5").Range(I & "2").Value) Then
 

Robert

XLDnaute Barbatruc
Repose en paix
Re : Boucle For sur Colonne

Bonjour le fil, bonjour le forum,

Dans ce cas... :
Code:
Dim I As Byte
For I = 1 to 26
Mais il faut remplacer partout les Range(I & "3") par Cells(3, I).
 
Dernière édition:

JNP

XLDnaute Barbatruc
Re : Boucle For sur Colonne

Bonsoir le fil :),
Comme ceci peut-être :rolleyes:
Code:
With Feuil5
    For I = 1 To 26
        If ComboBox1.Value = "416" Then
           If ComboBox2.Value = .Cells(2, 1) Then
             TextBox1.Value = .Cells(3, 1).Value
             TextBox2.Value = .Cells(4, 1).Value
             TextBox3.Value = .Cells(5, 1).Value
             TextBox4.Value = .Cells(6, 1).Value
             TextBox5.Value = .Cells(7, 1).Value
             TextBox6.Value = .Cells(8, 1).Value
             TextBox7.Value = .Cells(9, 1).Value
             TextBox8.Value = .Cells(10, 1).Value
           Else
            TextBox1.Value = ""
            TextBox2.Value = ""
            TextBox3.Value = ""
            TextBox4.Value = ""
            TextBox5.Value = ""
            TextBox6.Value = ""
            TextBox7.Value = ""
            TextBox8.Value = ""
          End If
        End If
    Next I
End With
Bonne suite :cool:
Ajout : Même pensée, même combat Robert :)
 

Robert

XLDnaute Barbatruc
Repose en paix
Re : Boucle For sur Colonne

Bonjour le fil, bonjour le forum,

Ou en simplifiant :
Code:
Dim I As Byte
Dim x As Byte

For I = A To Z
If ComboBox1.Value = "416" Then
    With Sheets("Feuil5")
        If ComboBox2.Value = CStr(.Cells(2, I).Value) Then
            For x = 1 To 8
                Me.Controls("TextBox" & x).Value = .Cells(x + 2, I).Value
            Next x
        Else
            For x = 1 To 8
                Me.Controls("TextBox" & x).Value = ""
            Next x
        End If
    End With
End If
Next I

[Edition]
Salut JNP on s'est croisé
 

raclette

XLDnaute Nouveau
Re : Boucle For sur Colonne

Salut Robert

grand merci après une petite modif :

Code:
Dim I As Integer
Dim x As Byte

For I = 1 To 100
If ComboBox1.Value = "416" Then
    With Feuil5
        If ComboBox2.Value = CStr(.Cells(2, I).Value) Then
            For x = 1 To 8
                Me.Controls("TextBox" & x).Value = .Cells(x + 2, I).Value
            Next x
        Else
            
        End If
    End With
End If

En fait la seconde partie effaçait les valeurs à chaque cycle.

Merci à toi
 
Dernière édition:

Discussions similaires

Réponses
6
Affichages
248
Réponses
11
Affichages
297

Statistiques des forums

Discussions
312 305
Messages
2 087 083
Membres
103 458
dernier inscrit
Vulgaris workshop