# Hello, how do I add column headers to listbox



## sofas (Dec 24, 2022)

```
Private Sub UserForm_Initialize()
 Set f = Sheets("bd")
 Set Rng = f.Range("A2:u" & f.[A65000].End(xlUp).Row)     ' à adapter
 NomTableau = "Tableau1"
 ActiveWorkbook.Names.Add Name:=NomTableau, RefersTo:=Rng                                     ' A adapter
 NbCol = Range(NomTableau).Columns.Count
 '---- A adapter
 TabBD = Range(NomTableau).Resize(, NbCol + 2).Value              ' Array: + rapide
 For i = 1 To UBound(TabBD): TabBD(i, NbCol + 1) = i: Next i      ' No enregistrement
 ColCombo = Array(2, 3, 4, 16, 15)                                ' A adapter (1 à 6 colonnes maxi)
 colVisu = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)     ' Colonnes ListBox (à adapter)
 colInterro = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) ' colonnes à interroger (adapter)
 '----
 NcolInt = UBound(colInterro) + 1
 Me.ListBox1.List = TabBD
 For i = UBound(ColCombo) + 1 To 5
   Me("combobox" & i + 1).Visible = False: Me("labelCbx" & i + 1).Visible = False
 Next i
 For c = 1 To UBound(ColCombo) + 1: Me("combobox" & c) = "*": Next c
 For c = 1 To UBound(ColCombo) + 1: ListeCol c: Next c
 For i = 1 To UBound(ColCombo) + 1:  Me("labelCbx" & i) = Range(NomTableau).Offset(-1).Item(1, ColCombo(i - 1)): Next i
 Me.ListBox1.ColumnCount = NbCol + 1
 '---dates
 colDate = 1
 Set d = CreateObject("scripting.dictionary")
 For i = LBound(TabBD) To UBound(TabBD)
    d(TabBD(i, colDate)) = ""
 Next i
 Dates = d.keys
 Tri Dates, LBound(Dates), UBound(Dates)
 Me.DateMini.List = Dates: Me.DateMini = Dates(0)
 Me.DateMaxi.List = Dates: Me.DateMaxi = Dates(UBound(Dates))
 
 

 Me.ComboTri.List = Application.Transpose(Range(NomTableau).Offset(-1).Resize(1))  ' Ordre tri
 Affiche
 B_ajout_Click
End Sub
```


----------



## Herakles (Dec 25, 2022)

Me.ListBox1.ColumnHeads = True


----------



## RoryA (Dec 25, 2022)

Your data must be in a range for columnheads to work.


----------



## Herakles (Dec 26, 2022)

What you can do is create a seperate listbox which has only one row of data, the values in each 
column being the column headers. Position this listbox immediately above and bordering the listbox 
containing the data. It can be made to look quite good.  

If the listbox containing the data needs to be scrolled horizontally, then column header listbox will not scroll
correspondingly.


----------

