Option Compare Text
Dim f, TblBD, ColVisu(), NbCol
Private Sub UserForm_Initialize()
Set f = Sheets("BD")
Set Rng = f.Range("A2:Z" & f.[A65000].End(xlUp).Row)
TblBD = Rng.Value ' rapidité
ColVisu = Array(1, 2, 3, 5, 6, 7, 8, 10, 11) ' Colonnes à visualiser (adapter)
NbCol = UBound(ColVisu) + 1
ReDim TblTitreListBox(1 To UBound(ColVisu) + 1)
TitreBD = Application.Transpose(Rng.Offset(-1).Resize(1).Value)
For i = LBound(ColVisu) To UBound(ColVisu)
TblTitreListBox(i + 1) = TitreBD(ColVisu(i), 1)
Next i
Me.ComboTri.List = TblTitreListBox
'---- Contenu ListBox initial
EnteteListBox
Affiche
End Sub
Private Sub TextBox1_Change()
Affiche
End Sub
Sub Affiche()
temp = "*" & Me.TextBox1 & "*"
Dim Tbl(): n = 0
For i = 1 To UBound(TblBD)
If TblBD(i, 11) Like temp Then
n = n + 1: ReDim Preserve Tbl(1 To NbCol, 1 To n)
c = 0
For Each k In ColVisu
c = c + 1: Tbl(c, n) = TblBD(i, k)
Next k
End If
Next i
If n > 0 Then Me.ListBox1.Column = Tbl Else Me.ListBox1.Clear
End Sub
Sub EnteteListBox()
x = Me.ListBox1.Left + 8
y = Me.ListBox1.Top - 12
For Each k In ColVisu
Set Lab = Me.Controls.Add("Forms.Label.1")
Lab.Caption = f.Cells(1, k)
Lab.Top = y
Lab.Left = x
x = x + f.Columns(k).Width * 1#
temp = temp & f.Columns(k).Width * 1# & ";"
Next
temp = Left(temp, Len(temp) - 1)
Me.ListBox1.ColumnCount = UBound(ColVisu) + 1
Me.ListBox1.ColumnWidths = temp
End Sub
Private Sub ComboTri_click()
Dim Tbl()
colTri = Me.ComboTri.ListIndex
Tbl = Me.ListBox1.List
TriMultiCol Tbl, LBound(Tbl), UBound(Tbl), colTri
Me.ListBox1.List = Tbl
End Sub
Sub TriMultiCol(a, gauc, droi, colTri) ' Quick sort
ref = a((gauc + droi) \ 2, colTri)
g = gauc: d = droi
Do
Do While a(g, colTri) < ref: g = g + 1: Loop
Do While ref < a(d, colTri): d = d - 1: Loop
If g <= d Then
For c = LBound(a, 2) To UBound(a, 2)
temp = a(g, c): a(g, c) = a(d, c): a(d, c) = temp
Next
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then TriMultiCol a, g, droi, colTri
If gauc < d Then TriMultiCol a, gauc, d, colTri
End Sub