Option Explicit
Public Function Alim_Combo(ByVal T As Variant, ByRef TabStrSearch As Variant) As Variant
Dim i As Long, j As Long, k As Byte
Dim Tablo(), Tmp, Sptd
x = 0
If NBrOpt = 3 Then
With UsF_Recherche
.CBn_Init = True
.Lbl_Info.Caption = ""
.Lbl_Info.ForeColor = &HFF&
NBrOpt = 0
Exit Function
End With
End If
' Saison 'N 'Equipe 'Domicile ou Exterieur
str = TabStrSearch(1, 1) & "!" & TabStrSearch(2, 1) & "!" & TabStrSearch(3, 1) & "!" & TabStrSearch(6, 1)
NBrOpt = 0 'remise à zero
For k = 1 To 6 'pour les 6 Colonnes
If k < 4 Or k = 6 Then 'si K = aux Colonnes 1,2,3,6
x = x + 1 'On incremente
Set Sptd = CreateObject("Scripting.Dictionary") 'avec le Dictionnaire ainsi définit
Sptd.Add IIf(k < 4 Or k = 6, "< TOUTES >", "< TOUS >"), IIf(k < 4 Or k = 6, "< TOUTES >", "< TOUS >") 'On entre la premiere Lignes qui correspond a "Toutes" et "Tous" en fonction des Colonnes
' With Ws_S
For Ligne = 2 To UBound(T, 1) 'pour chaque lignes du tableau
StrCompare = T(Ligne, 1) & "!" & T(Ligne, 2) & "!" & T(Ligne, 3) & "!" & T(Ligne, 6) '& "!" & T(Ligne, 9) & "!" & T(Ligne, 10)
If StrCompare Like str Then
If Not Sptd.Exists(T(Ligne, k)) Then Sptd.Add T(Ligne, k), T(Ligne, k)
End If
Next Ligne
Tablo = Sptd.items
For i = 1 To UBound(Tablo)
For j = 1 To UBound(Tablo)
If Tablo(i) < Tablo(j) Then
Tmp = Tablo(i)
Tablo(i) = Tablo(j)
Tablo(j) = Tmp 'IIf(x = 5 Or x = 6, Format(Tmp, "dd/mm/yyyy"), Tmp)
End If
Next j
Next i
' End With
With UsF_Recherche.Controls("CBx_" & x)
.Clear: EventOff = True
.List = Tablo
.Text = IIf(TabStrSearch(k, 1) = "*", TabStrSearch(k, 2), TabStrSearch(k, 1))
.ListRows = IIf(.ListCount > 25, 25, .ListCount)
If .ListCount = 2 Then
.ListIndex = 1
.BackColor = &HC0FFFF
.ForeColor = &HFF&
NBrOpt = NBrOpt + 1
GoTo suite
End If
.BackColor = IIf(TabStrSearch(k, 1) = "*", &HFF00&, &HC0FFFF)
.ForeColor = IIf(TabStrSearch(k, 1) = "*", &HFF0000, &HFF&)
suite:
TabStrSearch(k, 1) = IIf(InStr(1, .Text, "< TOU"), "*", .Text)
EventOff = False
If k < 4 Or k = 6 Then UsF_Recherche.Controls("LBl_Nbr_" & x) = .ListCount - 1
End With
Set Sptd = Nothing
Erase Tablo
End If
Next k
With UsF_Recherche
'ci dessous on colle le nombre d'item trouvés
.Lbl_Info.Caption = "Résultat du Filtre : " & .CBx_1.ListCount - 1 & " Ligne" & IIf(.CBx_1.ListCount - 1 = 1, "", "s") & " Trouvée" & IIf(.CBx_1.ListCount - 1 = 1, "", "s")
With .CBn_Init
.BackColor = IIf(NBrOpt > 0, &HFF00&, &H0&)
.ForeColor = IIf(NBrOpt > 0, &HFF&, &HFFFF&)
End With
End With
Alim_Combo = TabStrSearch
End Function
Public Function StSearch(ByRef TabStrSearch As Variant) As Variant
x = 0
For k = 1 To 6
If k < 4 Or k = 6 Then
x = x + 1
With UsF_Recherche.Controls("CBx_" & x) 'avec ce combobox
TabStrSearch(k, 1) = "" 'on vide la partie du tableau qui au départ contient "*"
TabStrSearch(k, 1) = IIf(InStr(1, .Text, "< TOU") <> 0, "*", .Text)
' TabStrSearch(k, 1) = IIf(InStr(1, .Text, "<< TOU") <> 0, "*", IIf(x > 4, Format(.Text, "00000"), .Text)) 'et on y colle ou la nouvelle valeur du Combobox
'ou "*" si valeur contient "<TOU"
End With
End If
Next k
StSearch = TabStrSearch
End Function