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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
Option Compare Text
Dim f, NomTableau, BD(), choix(), NcolInt, colVisu(), colInterro(), NbCol
Private Sub UserForm_Initialize()
NomTableau = "Tableau1" ' à Adapter
NbCol = Range(NomTableau).Columns.Count
BD = Range(NomTableau).Resize(, NbCol + 1).Value ' Array: + rapide
For i = 1 To UBound(BD): BD(i, NbCol + 1) = i: Next i ' No enregistrement
'--- à adapter
colInterro = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) ' colonnes à interroger (adapter)
colVisu = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) ' colonnes à visualiser dans listbox (adapter)
'----
NcolInt = UBound(colInterro) + 1
Me.ListBox1.ColumnCount = NbCol + 1
'-- génération de choix()
ReDim choix(1 To UBound(BD))
col = UBound(BD, 2)
For i = LBound(BD) To UBound(BD)
For Each k In colInterro
choix(i) = choix(i) & BD(i, k) & "|"
Next k
choix(i) = choix(i) & BD(i, col) & "|" ' no enreg
Next i
'--- valeurs initiales dans ListBox
Dim Tbl(): ReDim Tbl(1 To UBound(BD), 1 To NbCol + 1)
For i = 1 To UBound(BD)
For c = 1 To NbCol: Tbl(i, c) = BD(i, c): Next c
Tbl(i, c) = BD(i, NbCol + 1)
Next i
Me.ListBox1.List = Tbl
Me.ListBox1.ListIndex = -1
End Sub
Private Sub TextBoxRech_Change()
If Me.TextBoxRech <> "" Then
mots = Split(Trim(Me.TextBoxRech), " ")
Tbl = choix
For i = LBound(mots) To UBound(mots)
Tbl = Filter(Tbl, mots(i), True, vbTextCompare)
Next i
If UBound(Tbl) > -1 Then
Dim b(): ReDim b(1 To UBound(Tbl) + 1, 1 To NbCol + 1)
For i = LBound(Tbl) To UBound(Tbl)
a = Split(Tbl(i), "|")
j = a(NcolInt)
For c = 1 To NbCol: b(i + 1, c) = BD(j, c): Next c
b(i + 1, c) = j
Next i
Me.ListBox1.List = b
Else
Me.ListBox1.Clear
End If
Else
UserForm_Initialize
End If
End Sub |