Liste à choix multiple

Résolu/Fermé
juer31 Messages postés 107 Date d'inscription mercredi 16 décembre 2015 Statut Membre Dernière intervention 25 mars 2024 - 5 oct. 2017 à 21:06
juer31 Messages postés 107 Date d'inscription mercredi 16 décembre 2015 Statut Membre Dernière intervention 25 mars 2024 - 10 oct. 2017 à 16:43
Bonjour,

J'ai une liste a choix multiple (fait avec un userform) avec une liste de nom.
Lorsque j'ai fais mon choix, j'aimerais que pour chaque nom choisi, ceux-ci soit exporter sur des ligne séparer et nom une liste de nom dans une même cellule.

Est-ce possible?

Merci

Private Sub CommandButton1_Click()
'bouton valider
ActiveCell.Select
For k = 1 To ListBox1.ListCount - 1
If ListBox1.Selected(k) = True Then
tx = IIf(tx = "", ListBox1.List(k), tx & Chr(10) & ListBox1.List(k))
End If
Next
Application.EnableEvents = False
If xx <> "" And tx = "" Then ActiveCell.Value = xx
If xx = "" And tx <> "" Then ActiveCell.Value = tx
If xx <> "" And tx <> "" Then ActiveCell.Value = xx & Chr(10) & tx
If xx = "" And tx = "" Then ActiveCell.Value = ""
fin:
Application.EnableEvents = True
Unload UserForm2 'on ferme le formulaire
End Sub

Private Sub CommandButton2_Click()
Unload UserForm2 'on ferme le formulaire
End Sub

Private Sub ListBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 27 Then Unload UserForm2
End Sub

Private Sub UserForm_Activate()
Me.ListBox1.List = Feuil3.[D72:D188].Value
PauseTime = 1 ' Définit la durée.
Start = Timer ' Définit l'heure de début.
Do While Timer < Start + PauseTime
DoEvents ' Donne le contrôle à d'autres processus.
Loop
UserForm2.ListBox1.Enabled = True
ListBox1.SetFocus
End Sub

1 réponse

gbinforme Messages postés 14946 Date d'inscription lundi 18 octobre 2004 Statut Contributeur Dernière intervention 24 juin 2020 4 684
5 oct. 2017 à 21:34
Bonjour,

Ta validation modifiée selon ton souhait
Private Sub CommandButton1_Click()
'bouton valider
'ActiveCell.Select   ' inutile si activée elle est sélectionnée
ReDim tx(1 To 1)
For k = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(k) = True Then
    tx(UBound(tx)) = ListBox1.List(k)
    ReDim Preserve tx(1 To UBound(tx) + 1)
End If
Next
Application.EnableEvents = False
If xx <> "" And UBound(tx) = 1 Then ActiveCell.Value = xx
If xx = "" And UBound(tx) > 1 Then ActiveCell.Resize(UBound(tx), 1).Value = Application.Transpose(tx)
If xx <> "" And UBound(tx) > 1 Then ActiveCell.Value = xx: ActiveCell.Offset(1, 0).Resize(UBound(tx), 1).Value = Application.Transpose(tx)
If xx = "" And UBound(tx) = 1 Then ActiveCell.Value = ""
fin:
Application.EnableEvents = True
Unload UserForm2 'on ferme le formulaire
End Sub
0
juer31 Messages postés 107 Date d'inscription mercredi 16 décembre 2015 Statut Membre Dernière intervention 25 mars 2024 6
5 oct. 2017 à 22:00
Merci beaucoup

Tout est #1
0
juer31 Messages postés 107 Date d'inscription mercredi 16 décembre 2015 Statut Membre Dernière intervention 25 mars 2024 6
6 oct. 2017 à 20:01
Est-ce possible de le faire commencer la liste dans une cellule précise comme A6
0
gbinforme Messages postés 14946 Date d'inscription lundi 18 octobre 2004 Statut Contributeur Dernière intervention 24 juin 2020 4 684
6 oct. 2017 à 21:27
Bonsoir,

Il te suffit de remplacer 'ActiveCell' par '[A6]'
Private Sub CommandButton1_Click()
'bouton valider
ReDim tx(1 To 1)
For k = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(k) = True Then
    tx(UBound(tx)) = ListBox1.List(k)
    ReDim Preserve tx(1 To UBound(tx) + 1)
End If
Next
Application.EnableEvents = False
If xx <> "" And UBound(tx) = 1 Then [A6].Value = xx
If xx = "" And UBound(tx) > 1 Then [A6].Resize(UBound(tx), 1).Value = Application.Transpose(tx)
If xx <> "" And UBound(tx) > 1 Then [A6].Value = xx: [A6].Offset(1, 0).Resize(UBound(tx), 1).Value = Application.Transpose(tx)
If xx = "" And UBound(tx) = 1 Then [A6].Value = ""
fin:
Application.EnableEvents = True
Unload UserForm2 'on ferme le formulaire
End Sub
0
juer31 Messages postés 107 Date d'inscription mercredi 16 décembre 2015 Statut Membre Dernière intervention 25 mars 2024 6 > gbinforme Messages postés 14946 Date d'inscription lundi 18 octobre 2004 Statut Contributeur Dernière intervention 24 juin 2020
10 oct. 2017 à 16:43
Merci
0