' ZVI:2011-09-25 http://www.mrexcel.com/forum/showthread.php?t=581015
Option Explicit
' Init code
' There are data in Sheet1!A2:B6 for the testing of ListBox vs ListView
' RowSource of ListBox is set to Sheet1!A2:B6, A1:B1 is used for the headers
' ListVew control is populated via below code
Private Sub UserForm_Activate()
Dim a, r&, c&
' Copy range to array a()
With Sheets(1)
a = .Range(.Cells(.Rows.Count, "A").End(xlUp), "B1").Value
End With
' Populate ListView
With ListView1
' Empty ListView just for debug case
.ListItems.Clear
.ColumnHeaders.Clear
.Sorted = True
.Gridlines = True
' === Populate the 1st column of ListView
c = 1
' Add 1st header
.ColumnHeaders.Add , , a(1, c)
' Add items to the 1st column
For r = 2 To UBound(a)
.ListItems.Add , , a(r, c)
Next
' === Populate the 2nd column of ListView
c = c + 1
' Add 2nd header
.ColumnHeaders.Add , , a(1, c)
' Add items to the 2nd column
For r = 2 To UBound(a)
.ListItems(r - 1).SubItems(c - 1) = a(r, c)
Next
End With
End Sub
' OK button's code
Private Sub CommandButton1_Click()
Unload Me
End Sub