Boucle sur combobox
Bonjour,
Pourriez-vous svp m'éclairer sur la méthode pour faire une boucle sur une combobox ?
J'ai créé une userform qui me permet de compter des valeurs d'un tableau de la feuil3 selon la personne choisie dans la combobox et recopie le résultat dans un second tableau de la feuil3:
Cela marche parfaitement
Private Sub CBvalider_Click()
Dim Res As Integer
Dim dd As Integer
Dim ff1 As Integer
Dim ff2 As Integer
Dim col2 As Integer
dd = 0
Resultat = 0
With ThisWorkbook.Worksheets("Feuil3")
Set Plage = ThisWorkbook.Worksheets("Feuil3").Range("a5:a40")
For Each Cell In Plage
If Cell.Value = ComboBox1.Value Then ' si = au nom de la liste
lig = Cell.Row ' lig = au numéro de ligne de la feuil1
End If
Next Cell
End With
With ThisWorkbook.Worksheets("Feuil3")
Set plage2 = ThisWorkbook.Worksheets("Feuil3").Range("c5:ov5")
For Each Cell In plage2
If Cell.Value >= CDate(DDeb.Value) And Cell.Value <= CDate(DFin.Value) Then
col1 = Cell.Column + 1
col = Mid(Cell.Address, 2, InStr(2, Cell.Address, "$") - 2)
If Cells(lig, col1).Value <> "" Then
dd = Cells(lig, col1).Value
Resultat = Resultat + dd
End If
If Cells(lig + 1, col1).Value <> "" Then
dd1 = Cells(lig + 1, col1).Value
Resultat = Resultat + dd1
End If
End If
Next Cell
End With
ff2 = TextBox1.Value
With ThisWorkbook.Worksheets("Feuil3")
Set Plage4 = ThisWorkbook.Worksheets("Feuil3").Range("a45:q45")
For Each Cell In Plage4
If Cell.Value = ff2 Then ' si = au nom de la liste
col2 = Cell.Column
End If
Next Cell
End With
With ThisWorkbook.Worksheets("Feuil3")
Set Plage3 = ThisWorkbook.Worksheets("Feuil3").Range("a47:a64")
For Each Cell In Plage3
If Cell.Value = ComboBox1.Value Then ' si = au nom de la liste
lig1 = Cell.Row ' lig = au numéro de ligne de la feuil1
ff1 = TextBox1.Value
Cells(lig1, col2).Value = Resultat
End If
Next Cell
End With
MsgBox Resultat
End Sub
Je voudrais faire ce calcul pour toutes les personnes de la combobox.
J'ai essayé (une partie) avec un autre bouton de commande en utilisant
For i = 0 To ComboBox1.Items.Count - 1
MsgBox (i & " : " & Me.ComboBox1.Items(i))
next i
mais j'ai cette erreur
"erreur de compilation - membre de méthode ou de donnée introuvable"
je ne comprends pas mon erreur :
Private Sub CommandButton1_Click()
Dim Res As Integer
Dim dd As Integer
Dim ff1 As Integer
Dim ff2 As Integer
Dim col2 As Integer
dd = 0
Resultat = 0
For i = 0 To ComboBox1.Items.Count - 1
MsgBox (i & " : " & Me.ComboBox1.Items(i))
With ThisWorkbook.Worksheets("Feuil3")
Set Plage = ThisWorkbook.Worksheets("Feuil3").Range("a5:a40")
For Each Cell In Plage
If Cell.Value = ComboBox1.Items(i) Then ' si = au nom de la liste
lig = Cell.Row ' lig = au numéro de ligne de la feuil1
End If
Next Cell
End With
With ThisWorkbook.Worksheets("Feuil3")
Set plage2 = ThisWorkbook.Worksheets("Feuil3").Range("c5:ov5")
For Each Cell In plage2
If Cell.Value >= CDate(DDeb.Value) And Cell.Value <= CDate(DFin.Value) Then
col1 = Cell.Column + 1
col = Mid(Cell.Address, 2, InStr(2, Cell.Address, "$") - 2)
If Cells(lig, col1).Value <> "" Then
dd = Cells(lig, col1).Value
Resultat = Resultat + dd
End If
If Cells(lig + 1, col1).Value <> "" Then
dd1 = Cells(lig + 1, col1).Value
Resultat = Resultat + dd1
End If
End If
Next Cell
End With
Next i
MsgBox Resultat
End Sub
Pourriez-vous svp m'aider ?
Je vous remercie beaucoup
Cordialement
Salut Sylvain,
Bonjour le Forum,
Ce n'est pas Index
qu'il faut utiliser mais List
avec une ComboBox :
For i = 0 To ComboBox1.ListCount
MsgBox ComboBox1.List(i)
Next
A dispo
Merci
Je vous suis trés reconnaissant
Bonne journée