XL 2010 Sélectionner listbox selon choix Combobox

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Appo1985

XLDnaute Occasionnel
Bonjour à tous.
Merci à @laurent950 et à @job75 qui m’ont aidé avec le bouton « Modifier ».
Je voudrais de l’aide avec Combobox1_Change.
En choisissant le matricule je voudrais afficher les critères étaient affectés dans le listbox afin d’ajouter un ou des critères. Actuellement quand je ferme le userfom et je l’ouvre je ne connais pas les critères pour chaque numéro et si je valide un critère les autres s’effacent alors que je voudrais ajouter.
J’ai ajouté ci-joint mon fichier et un autre fichier exemple que j’ai téléchargé sur le site boisgontierj.free.fr pour que vous puissiez voir le comportement du listbox « Loisirs ».
Merci par avance.
 

Pièces jointes

Solution
Bonjour Appo1985, le forum,

Voyez le code de l'UserForm :
VB:
Const sep$ = " ; "

Private Sub ComboBox1_Change()
Dim i&, x$, j&
i = ComboBox1.ListIndex + 1
If i = 0 Then ComboBox1 = "": ComboBox1.DropDown: Exit Sub
x = sep & [Tableau1].Cells(i, 17) & sep
With ListBox1
    For j = 0 To ListBox1.ListCount - 1
        .Selected(j) = False 'RAZ
        If InStr(x, sep & .List(j, 0) & sep) Then .Selected(j) = True
    Next
End With
End Sub

Private Sub CommandButton1_Click()
Dim i&, j&, x$
i = ComboBox1.ListIndex + 1
If i = 0 Then Exit Sub
With ListBox1
    For j = 0 To ListBox1.ListCount - 1
        If .Selected(j) Then x = x & sep & .List(j, 0)
    Next
End With
[Tableau1].Cells(i, 17) = Mid(x, Len(sep) + 1)
Unload Me
End Sub
A+
Bonjour Appo1985, le forum,

Voyez le code de l'UserForm :
VB:
Const sep$ = " ; "

Private Sub ComboBox1_Change()
Dim i&, x$, j&
i = ComboBox1.ListIndex + 1
If i = 0 Then ComboBox1 = "": ComboBox1.DropDown: Exit Sub
x = sep & [Tableau1].Cells(i, 17) & sep
With ListBox1
    For j = 0 To ListBox1.ListCount - 1
        .Selected(j) = False 'RAZ
        If InStr(x, sep & .List(j, 0) & sep) Then .Selected(j) = True
    Next
End With
End Sub

Private Sub CommandButton1_Click()
Dim i&, j&, x$
i = ComboBox1.ListIndex + 1
If i = 0 Then Exit Sub
With ListBox1
    For j = 0 To ListBox1.ListCount - 1
        If .Selected(j) Then x = x & sep & .List(j, 0)
    Next
End With
[Tableau1].Cells(i, 17) = Mid(x, Len(sep) + 1)
Unload Me
End Sub
A+
 

Pièces jointes

Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
4
Affichages
451
Retour