Hello, how do I add column headers to listbox

sofas

Active Member
Joined
Sep 11, 2022
Messages
493
Office Version
  1. 2019
Platform
  1. Windows
VBA Code:
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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Your data must be in a range for columnheads to work.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,020
Members
449,480
Latest member
yesitisasport

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