1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
   | Private Sub UserForm_Click()
Dim iRow As Integer
Dim TheCell As Range
 
'On pointe la feuille contenant les données
With ThisWorkbook.Sheets("Analytique")
    'On place les entêtes
    For Each TheCell In .Range("A1", .Cells(1, .Columns.Count).End(xlToLeft))
        ListView1.ColumnHeaders.Add , , TheCell.Value
    Next
    'On place les données (ici, la colonne A ne doit jamais avoir de vide (sinon prendre une autre colonne)
    For iRow = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
        'On ajoute une ligne
        ListView1.ListItems.Add , , .Cells(iRow, "A").Value
        'On y place les données
        'On boucle sur les cellule de la ligne iRow
        For Each TheCell In .Range(.Cells(iRow, "B"), .Cells(iRow, .Columns.Count).End(xlToLeft))
            ListView1.ListItems(iRow - 1).ListSubItems.Add , , TheCell.Value
        Next
    Next
End With
 
End Sub | 
Partager