Bonjour
Alors voilà, j'ai un UserForm avec une ListBox alimentée depuis une feuille du classeur. Il s’agit d'un tableau et ce dernier et très large. A l’initialisation du UserForm la ListBox affiche le tableau avec une ScrollBar vertical pour se déplacer.
De plus à l’initialisation, un Label est créé avec les entêtes des colonnes du tableau. Comme le tableau est très larges les entêtes ne passent pas tous dans le USerForm.
Ce que je voudrais faire, si possible, et que quand je scroll la barre verticale de la LisBox, récupérer la position de la ScrollBar pour l'appliquer au Label. Ainsi le Label se déplace et les entête restent alignées aux colonnes de la ListBox !
J'espère avoir été clair ! Je met une partie du code utilisé.
Par avance, merci de l’intérêt porté au sujet
INITIALISATION DE LA LISTBOX A L'OUVERTURE DU USERFORM
Set f = Feuil1
Set Rng = f.Range("A2:AG" & f.[A65000].End(xlUp).Row)
Titre = f.UsedRange.Rows(1).Value
NomTableau = "Tableau1"
ActiveWorkbook.Names.Add Name:=NomTableau, RefersTo:=Rng
NbCol = Range(NomTableau).Columns.Count
TabBD = Range(NomTableau).Resize(, NbCol + 1).Value
For i = 1 To UBound(TabBD): TabBD(i, NbCol + 1) = i: Next i
colVisu = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)
Me.ListBox1.List = TabBD
Me.ListBox1.ColumnCount = NbCol + 1
EnteteListBox
CRÉATION DE L’ENTÊTE APRES INITIALISATION
Sub EnteteListBox()
X = Me.ListBox1.Left + 8
Y = Me.ListBox1.Top - 15
For c = 1 To NbCol
pos = Application.Match(c, colVisu, 0)
If Not IsError(pos) Then
'k = c
Set Lab = Me.Controls.Add("Forms.Label.1")
Lab.Caption = Range(NomTableau).Offset(-1).Item(1, c)
Lab.ForeColor = vbBlack
Lab.Top = Y
Lab.Left = X
Lab.Height = 24
Lab.Width = Range(NomTableau).Columns(c).Width * 1#
X = X + Range(NomTableau).Columns(c).Width * 1
tempcol = tempcol & Range(NomTableau).Columns(c).Width * 1# & ";"
Else
X = X + 0
tempcol = tempcol & 0 & ";"
End If
Next c
tempcol = tempcol & "20"
On Error Resume Next
Me.ListBox1.ColumnWidths = tempcol
On Error GoTo 0
End Sub