Dear friends,
Is it possible to populate a listview from three sheets with the same headers in one workbook0Currently I am using this code:
'Populate Listview Dim ws As Worksheet
Dim lngRow As Long
Dim lvwItem As listItem
Dim lngEndCol As Long
Dim lngCol As Long
Dim lngEndRow As Long
Dim lngItemIndex As Long
Dim blnHeaders() As Boolean
Set ws = Array("Basic to Sustain", "Specific to sustain", "Improve-performance")
lngEndCol = ws.Range("A1").End(xlToRight).Column
lngEndRow = ws.Range("A1").End(xlDown).Row
lngRow = 1
With ListView1
.View = lvwReport
ReDim blnHeaders(1 To lngEndCol)
For lngCol = 1 To lngEndCol
If Application.WorksheetFunction.CountA(ws.Range(ws.Cells(1, lngCol), ws.Cells(lngEndRow, lngCol))) > 1 Then
.ColumnHeaders.Add , , ws.Cells(lngRow, lngCol).Value, ws.Columns(lngCol).ColumnWidth * 10
blnHeaders(lngCol) = True
End If
Next
For lngRow = 2 To lngEndRow
lngCol = 1
lngItemIndex = 0
Set lvwItem = .ListItems.Add(, , ws.Cells(lngRow, lngCol).Value)
For lngCol = 2 To lngEndCol
If blnHeaders(lngCol) Then
lngItemIndex = lngItemIndex + 1
lvwItem.SubItems(lngItemIndex) = ws.Cells(lngRow, lngCol).Value 'Adds Value from Current Row and Column 1
End If
Next
Next
End With
But it seems not working and gives "run time error 424-object required"
Here is a screenshot as well as my sample data attached:
error.jpg