ComboBox
Résolu
ti_mouton
Messages postés
153
Statut
Membre
-
pijaku Messages postés 13513 Statut Modérateur -
pijaku Messages postés 13513 Statut Modérateur -
Bonjour,
J'ai un userform avec plusieurs Combobox, les ComboBox 3 et 4 sont liées et la combobox 5 qui elle est indépendante des autres. Je voudrais rajouter un code qui fasse en sorte que lorsqu'il n'y a qu'un seul choix possible pour cette combobox il se selectionne automatiquement? J'ai tenté quelques codes avec ce que j'ai pu trouver sur ce forum mais sans succès...
Merci pour votre aide,
J'ai un userform avec plusieurs Combobox, les ComboBox 3 et 4 sont liées et la combobox 5 qui elle est indépendante des autres. Je voudrais rajouter un code qui fasse en sorte que lorsqu'il n'y a qu'un seul choix possible pour cette combobox il se selectionne automatiquement? J'ai tenté quelques codes avec ce que j'ai pu trouver sur ce forum mais sans succès...
Private Sub Userform_Initialize()
Set f = Sheets("BDD")
Set mondico = CreateObject("Scripting.Dictionary")
For Each C In f.Range("C3:C" & f.[A65000].End(xlUp).Row)
mondico(C.Value) = ""
Next C
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox3.List = temp
End Sub
Private Sub ComboBox3_click()
Me.ComboBox4.Clear
Set mondico = CreateObject("Scripting.Dictionary")
For Each C In f.Range("C3:C" & f.[A65000].End(xlUp).Row)
If C = Me.ComboBox3 Then mondico(C.Offset(, 1).Value) = ""
Next C
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox4.List = temp
If Me.ComboBox4.ListCount = 1 Then Me.ComboBox4.ListIndex = 0
End Sub
Private Sub ComboBox5_Click()
Sheets("BDD").Select
ComboBox5.List = Range("E3:E" & f.[A65000].End(xlUp).Row).Value
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox5.List = temp
If Me.ComboBox5.ListCount = 1 Then Me.ComboBox5.ListIndex = 0
End Sub
Sub Tri(a, gauc, droi) ' Quick sort
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi)
If gauc < d Then Call Tri(a, gauc, d)
End Sub
Merci pour votre aide,
2 réponses
Bonjour,
Et si, avant de poser une nouvelle question, tu allais répondre à tes sujets en cours :
https://forums.commentcamarche.net/forum/affich-32119334-erreur-70-permission-refusee
Et si, avant de poser une nouvelle question, tu allais répondre à tes sujets en cours :
https://forums.commentcamarche.net/forum/affich-32119334-erreur-70-permission-refusee
ti_mouton
Messages postés
153
Statut
Membre
Excuses moi, je pensais t'avoir répondu mais visiblement j'ai du faire une fausse manip ou oublié de valider ma réponse...
Pas de souci.
C'est fait.
Pour te répondre donc aujourd'hui.
Quel est l'événement qui, jusqu'à maintenant, remplit ta ComboBox5?
L'événement ComboBox5_Click.
Or, aujourd'hui, tu souhaiterais qu'elle soit "pré-remplie" si elle n'a qu'un seul élément.
Il te faut trouver donc l'événement déclencheur de cela.
Par exemple, tu peut ajouter le remplissage de ta combobox5 dans l'événement Initialize de l'UserForm.
La globalité de ton code donné plus haut deviendrait donc :
A tester...
C'est fait.
Pour te répondre donc aujourd'hui.
Quel est l'événement qui, jusqu'à maintenant, remplit ta ComboBox5?
L'événement ComboBox5_Click.
Or, aujourd'hui, tu souhaiterais qu'elle soit "pré-remplie" si elle n'a qu'un seul élément.
Il te faut trouver donc l'événement déclencheur de cela.
Par exemple, tu peut ajouter le remplissage de ta combobox5 dans l'événement Initialize de l'UserForm.
La globalité de ton code donné plus haut deviendrait donc :
Private Sub Userform_Initialize()
Set f = Sheets("BDD")
Set mondico = CreateObject("Scripting.Dictionary")
For Each C In f.Range("C3:C" & f.[A65000].End(xlUp).Row)
mondico(C.Value) = ""
Next C
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox3.List = temp
Set mondico = CreateObject("Scripting.Dictionary")
For Each C In f.Range("E3:E" & f.[A65000].End(xlUp).Row)
mondico(C.Value) = ""
Next C
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox5.List = temp
If Me.ComboBox5.ListCount = 1 Then Me.ComboBox5.ListIndex = 0
End Sub
Private Sub ComboBox3_click()
Me.ComboBox4.Clear
Set mondico = CreateObject("Scripting.Dictionary")
For Each C In f.Range("C3:C" & f.[A65000].End(xlUp).Row)
If C = Me.ComboBox3 Then mondico(C.Offset(, 1).Value) = ""
Next C
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox4.List = temp
If Me.ComboBox4.ListCount = 1 Then Me.ComboBox4.ListIndex = 0
End Sub
Private Sub ComboBox5_Click()
End Sub
Sub Tri(a, gauc, droi) ' Quick sort
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi)
If gauc < d Then Call Tri(a, gauc, d)
End Sub
A tester...