Liste à choix multiple

Résolu
juer31 Messages postés 120 Statut Membre -  
juer31 Messages postés 120 Statut Membre -
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

  1. gbinforme Messages postés 14930 Date d'inscription   Statut Contributeur Dernière intervention   4 744
     
    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
    1. juer31 Messages postés 120 Statut Membre 6
       
      Merci beaucoup

      Tout est #1
      0
    2. juer31 Messages postés 120 Statut Membre 6
       
      Est-ce possible de le faire commencer la liste dans une cellule précise comme A6
      0
    3. gbinforme Messages postés 14930 Date d'inscription   Statut Contributeur Dernière intervention   4 744
       
      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
      1. juer31 Messages postés 120 Statut Membre 6 > gbinforme Messages postés 14930 Date d'inscription   Statut Contributeur Dernière intervention  
         
        Merci
        0