problème compilation listbox pour choix multiples
Bonjour à tous,
Je reviens encore vers vous pour un problème de listebox ...
J'ai actuellement un besoin de faire des choix multiples en cliquant sur une cellule (n'importe laquelle). Grâce à la magie internet, j'ai trouver une solution pour ouvrir une listbox.
Dans un premier temps j'ai donc créer 1 liste dans l'onglet excel "Listes" avec la fonction excel "gestionnaire de nom" :
Code:
1 2
|
Liste : =DECALER(Listes!$A$2;;;NBVAL(Listes!$A:$A)-1) |
Le premier code de ma userform fonctionnant lorsque je n'avais qu'une liste était le suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
Option Explicit
Private Sub CommandButton1_Click()
Dim i As Byte
Dim Choix As String
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
Choix = Choix & ListBox1.List(i) & " / "
End If
Next i
ActiveCell = Left(Choix, Len(Choix) - 2)
Unload UserForm1
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer
ListBox1.Clear
ListBox1.List() = Range("Liste").Value 'Nom défini = Liste
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
ListBox1.Selected(i) = False
End If
Next i
End Sub |
Mon besoin maintenant est de pouvoir toujours en cliquant sur une cellule, de pouvoir compiler 2 listebox sur un même userform.
Pour satisfaire mon besoin, j'ai donc créer 2 listes avec la fonction excel "gestionnaire de nom" :
Code:
1 2 3
|
Liste : =DECALER(Listes!$A$2;;;NBVAL(Listes!$A:$A)-1)
Liste2 : =DECALER(Listes!$C$2;;;NBVAL(Listes!$C:$C)-1) |
Puis modifier la userform en ayant un listbox1 et un listbox2. Ensuite j'ai fais une modification du programme de la sorte :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
Option Explicit
Private Sub CommandButton1_Click()
Dim i As Byte
Dim j As Byte
Dim Choix1 As String
Dim Choix2 As String
For j = 0 To ListBox1.ListCount - 1
For i = 0 To ListBox2.ListCount - 1
If ListBox1.Selected(i) = True Then
Choix1 = Choix1 & ListBox1.List(i) & " : "
End If
If ListBox2.Selected(i) = True Then
Choix2 = Choix2 & ListBox2.List(i) & " / "
End If
Next i
Next j
ActiveCell = Left(Choix1, Len(Choix1) - 2)
Unload UserForm1
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer
Dim j As Integer
ListBox1.Clear
ListBox2.Clear
ListBox1.List() = Range("Liste2").Value 'Nom défini = Liste
ListBox2.List() = Range("Liste").Value 'Nom défini = Liste
For j = 0 To ListBox1.ListCount - 1
For i = 0 To ListBox2.ListCount - 1
If ListBox1.Selected(i) = True Then
ListBox1.Selected(i) = False
End If
If ListBox2.Selected(i) = True Then
ListBox2.Selected(i) = False
End If
Next i
Next j
End Sub |
L'affichage des deux listes se fait bien dans ma seule userform dans deux encart listbox1 et listbox2 mais je n'arrive pas à les compiler de sorte que dans la cellule excel selectionnée soit affiché "ChoixMultipleListbox1 : ChoixMultipleListbox2"
Si quelqu'un sait m'aider ...
Merci d'avance.