Populate List View With Coloumn Header From Spreadsheets

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
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:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,214,788
Messages
6,121,582
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top