I have multiple sheets, each with 1 only 1 table at various widths and heights.
I am trying to achive: once user have selected sheet via combobox, (this works) then i can list the headers from the table on that sheet.
my possible solution idea: My idea was to list the table headers in a combobox on a userform.
- i count columns on selected sheet, works
- for loop through the columns to grab the header name from each and stack into combobox.list,
code:
Private Sub chcSite_Change()
Dim siteSheet As String
siteSheet = WorksheetFunction.VLookup(Me.chcSite.Value, Worksheets("Overview").Range("SiteTable"), 2, False)
Me.chcRange.Enabled = True ' enables combobox for headers list
Dim COLS As Integer
COLS = Worksheets(siteSheet).ListObjects(1).ListColumns.Count
Dim i As Integer
i = 1
For i = 1 To COLS
If Worksheets(siteSheet).Cells(Columns(i), 1) = "" Then Exit For ' if header is empty = also end of table cols.
MsgBox Worksheets(siteSheet).Cells(Columns(i), 1) ' debug to see what it returns.
Next i
'Me.chcRange.List = Worksheets(siteSheet).ListObjects(1).ColumnHeads ' random test of columnheads
End Sub
as you can see i was exspecting Worksheets(siteSheet).Cells(Columns(i), 1) to return something, but it appears it is only a pointer/selector.