I've added this code to my worksheet as a test, it worked fine on the sample workbook, but when I run the same code in my production workbook I get an error. The userform and listview were duplicated in the prod workbook. I did notice that when I try to manually add a Listview control v6.0 to the userform, I get a blank. When I try clicking on where the listview should be in the userform I get a Library not registered error. I have scrubbed most of the VBA code and userforms from the attached file "LISTVIEW NOT WORKING.xlsm" so you can compare the 2 spreadsheets (they should be the same, but one works and the other does not).
Private Sub LoadListView()
'Declare the variables
Dim wksSource As Worksheet
Dim rngData As Range
Dim rngCell As Range
Dim LstItem As ListItem
Dim RowCount As Long
Dim ColCount As Long
Dim i As Long
Dim j As Long
'Set the source worksheet
Set wksSource = Worksheets("THistory")
'Set the source range
Set rngData = wksSource.Range("A1").CurrentRegion
'Add the column headers
For Each rngCell In rngData.Rows(1).Cells
Form3.ListView1.ColumnHeaders.Add Text:=rngCell.Value, Width:=90
Next rngCell
'Count the number of rows in the source range
RowCount = rngData.Rows.Count
'Count the number of columns in the source range
ColCount = rngData.Columns.Count
'Fill the ListView
For i = 2 To RowCount
Set LstItem = Form3.ListView1.ListItems.Add(Text:=rngData(i, 1).Value) ' THIS IS WHERE I GET THE ERROR!!!
'LstItem.ForeColor = vbBlue
For j = 2 To ColCount
'LstItem.ForeColor = vbRed
LstItem.ListSubItems.Add Text:=rngData(i, j).Value
Next j
Next i
End Sub
Bookmarks