Pb de Listbox

Ratatouil

XLDnaute Nouveau
Bonsoir à tous,
j'ai un petit souci avec ma listbox, en fait je voudrai savoir comment affecter plusieurs données d'une listbox à plusieurs colonnes dans un tableau exel.
Merci d'avance et bonne soirée.
 

Pièces jointes

  • Nouveau Dossier compressé.zip
    8.3 KB · Affichages: 16
  • Nouveau Dossier compressé.zip
    8.3 KB · Affichages: 15
  • Nouveau Dossier compressé.zip
    8.3 KB · Affichages: 17

bqtr

XLDnaute Accro
Re : Pb de Listbox

Bonsoir Ratatouil

Voici une proposition pour le bouton valider :

Code:
Private Sub CommandButton1_Click()

Dim m As Long

If ListBox1.ListIndex = -1 Then Exit Sub

If CheckBox1 Then
    With Sheets(CheckBox1.Caption)
        m = 1
        For i = 0 To ListBox1.ListCount - 1
          If ListBox1.Selected(i) Then
             .Range("A" & m) = ListBox1.List(i, 0)
             .Range("B" & m) = ListBox1.List(i, 1)
             .Range("C" & m) = ListBox1.List(i, 2)
             m = m + 1
          End If
        Next
    End With
End If

If CheckBox2 Then
    With Sheets(CheckBox2.Caption)
        m = 1
        For i = 0 To ListBox1.ListCount - 1
          If ListBox1.Selected(i) Then
             .Range("A" & m) = ListBox1.List(i, 0)
             .Range("B" & m) = ListBox1.List(i, 1)
             .Range("C" & m) = ListBox1.List(i, 2)
             m = m + 1
          End If
        Next
    End With
End If
Unload Me

End Sub

Les données se mettent à partir de la ligne 1 (m=1).

A+