代码如下。。。
Private Sub UserForm_Initialize()
Set wb = ThisWorkbook
Set sht = wb.Sheets("sheet1")
arr = sht.[a1].CurrentRegion
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear
ListView1.View = lvwReport
ListView1.Gridlines = True
ListView1.LabelEdit = lvwManual
ListView1.FullRowSelect = True
ListView1.ColumnHeaders.Add 1, , arr(1, 1), sht.Cells(1, 1).Width
ListView1.ColumnHeaders.Add 2, , arr(1, 2), sht.Cells(1, 2).Width
ListView1.ColumnHeaders.Add 3, , arr(1, 3), sht.Cells(1, 3).Width
ListView1.ColumnHeaders.Add 4, , arr(1, 4), sht.Cells(1, 4).Width
ListView1.ColumnHeaders.Add 5, , arr(1, 5), sht.Cells(1, 5).Width
ListView1.ColumnHeaders.Add 6, , arr(1, 6), sht.Cells(1, 6).Width
ListView1.ColumnHeaders.Add 7, , arr(1, 7), sht.Cells(1, 7).Width
Dim itm As ListItem, list
For i = 2 To UBound(arr)
If s = arr(i, 2) Then
Set itm = ListView1.ListItems.Add()
itm.Text = arr(i, 1)
For j = 1 To UBound(arr, 2) - 1
itm.SubItems(j) = arr(i, j + 1)
Next
End If
Next
End Sub
|