Populate List View With Coloumn Header From Spreadsheets

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
53
I made this code below, and I am asking if anyone knows how to fix it, when I press on the command button an error shows up? I want to populate the list view with the table headers.


Code:
Private Sub CommandButton1_Click()
    With ListView1Headers
   .View = lvwReport
   .CheckBoxes = True
   .FullRowSelect = True
   .Gridlines = True
   With .ColumnHeaders
      .Clear
      .Add , , "Column Title Headers", 128
'      .Add , , "Subitem-1", 70
'      .Add , , "Subitem-2", 70
   End With

    End With
    
    
    
    
   Me.ListView1Headers.Clear

mySheet = Me.ComboBox1.Value
'On Error Resume Next
lastCol = ThisWorkbook.Sheets(mySheet).Cells(TextBox1.Value, Columns.Count).End(xlToLeft).Column

For x = 1 To lastCol
    Me.ListView1Headers.ListItems.Add ThisWorkbook.Sheets(mySheet).Cells(TextBox1.Value, x)
Next x


End Sub

Here is a table for reference:

ABCDE
1
2Header1
Header2

<tbody>
</tbody>
Header3

<tbody>
</tbody>
Header4

<tbody>
</tbody>
Header5

<tbody>
</tbody>
3
4

<tbody>
</tbody>


I am trying to get the code to populate the List View with table headers name.


Thank You
 
Last edited:

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
53
Never mind, I have figured it out, so no one needs to reply back.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,579
Messages
5,523,695
Members
409,531
Latest member
wo1f

This Week's Hot Topics

Top