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:

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Header1[/TD]
[TD]
Header2

<tbody>
</tbody>
[/TD]
[TD]
Header3

<tbody>
</tbody>
[/TD]
[TD]
Header4

<tbody>
</tbody>
[/TD]
[TD]
Header5

<tbody>
</tbody>
[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


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


Thank You
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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