For Each In colonne?

laurent45

XLDnaute Occasionnel
Bonsoir le Forum,

Voilà, aujourd'hui, je cherche à créer une boucle For Each dans une colonne, mais cette colonne n'est jamais la même.

L'USF ci-joint récupère les noms de plat dans la Range("C2:CO2").
Ce que je souhaite, c'est que lors de la sélection d'un plat (Plat_CBx_Change()), les comboBox(1-10) affichent les ingrédients contenu dans le plat.
Chaque ComboBox a cette, info lors de l'Initialize de l'USF.

Le problème, c'est mon code :
Code:
Private Sub Plat_CBx_Click()
For Each cel In Dispatching.Range("C2:CO2")
     If cel = Plat_CBx Then col = cel.column
Next cel

For i = 1 To 10
     For Each cel In DISPATCHING.Columns(col)
          If IsEmpty(cel) = False Then
               If cel.Row > DISPATCHING.Range("A65535").End(xlUp).Row then Exit Sub
               If cel.Row >= 4 Then
                    With Me
                         .Controls("ComboBox" & i).Value = DISPATCHING.Cells(cel.Row, 1)
                         .Controls("TextBox" & i).Value = DISPATCHING.Cells(cel.Row, 2)
                         .Controls("TextBox1" & i).Value = DISPATCHING.Cells(cel.Row, col)
                    End With
               End If
          End If
     Next cel
Next i
End Sub
La valeur de cel.row reste à 1 et la boucle cel fonctionne une fois et c'est fini... J'ai l'impression que c'est la définition de la colonne qui n'est pas bonne.

Merci de votre aide

Laurent
 

Pièces jointes

  • Test.zip
    28.4 KB · Affichages: 45
  • Test.zip
    28.4 KB · Affichages: 52
  • Test.zip
    28.4 KB · Affichages: 50
Dernière édition:

lapix

XLDnaute Occasionnel
Re : For Each In colonne?

Bonsoir,

Ta procedure un peu modifiée. Tu as un probleme avec l'enchainement du for i et for each

Corrigé :

Private Sub Plat_CBx_Click()
For Each cel In DISPATCHING.Range("C2:CO2")
If cel = Plat_CBx Then col = cel.Column: Exit For
Next cel

i = 1

For Each cel In DISPATCHING.Range(Cells(4, col), Cells(108, col))
If IsEmpty(cel) = False Then
'If cel.Row > DISPATCHING.Range("A65535").End(xlUp).Row Then Exit Sub
'If cel.Row >= 4 Then
With Me
.Controls("ComboBox" & i).Value = DISPATCHING.Cells(cel.Row, 1)
.Controls("TextBox" & i).Value = DISPATCHING.Cells(cel.Row, 2)
.Controls("TextBox1" & i).Value = DISPATCHING.Cells(cel.Row, col)
i = i + 1
If i = 11 Then Exit For
End With
'End If
End If
Next cel
End Sub


ah ! trop tard !
Pas vu lacorse33. Un petit coucou alors et bonne soiree
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 413
Messages
2 088 195
Membres
103 755
dernier inscrit
Nicolas TULENGE