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
|
Function FiltreMultiCrit2(Tbl, colCle1, Cle1, ColResult, Optional colCle2, Optional Cle2, Optional ColTri)
Dim b()
ligne = 1
If IsMissing(colCle2) Then colCle2 = colCle1: Cle2 = Cle1
For i = LBound(Tbl) To UBound(Tbl)
' If Tbl(i, colClé1) = Clé1 And Tbl(i, colClé2) = Clé2 Then n = n + 1
If InStr(1, Tbl(i, colCle1), Cle1, vbTextCompare) > 0 And InStr(1, Tbl(i, colCle2), Cle2, vbTextCompare) > 0 Then n = n + 1 ' Instr pour dire que Clé1 et Clé2 COMPREND la chaîne de caractère
Next i
If n > 0 Then
If IsArray(ColResult) Then
ReDim b(LBound(Tbl) To n, LBound(ColResult) + 1 To UBound(ColResult) - LBound(ColResult) + 1)
Else
ReDim b(LBound(Tbl) To n, 1 To 1)
End If
For i = LBound(Tbl, 1) To UBound(Tbl, 1)
' If Tbl(i, colClé1) = Clé1 And Tbl(i, colClé2) = Clé2 Then
If InStr(1, Tbl(i, colCle1), Cle1, vbTextCompare) > 0 And InStr(1, Tbl(i, colCle2), Cle2, vbTextCompare) > 0 Then
If IsArray(ColResult) Then
For c = LBound(ColResult) To UBound(ColResult)
col = ColResult(c)
b(ligne, c + 1) = Tbl(i, col)
Next c
Else
b(ligne, ColResult) = Tbl(i, ColResult)
End If
ligne = ligne + 1
End If
Next i
If Not IsMissing(ColTri) Then Call TriCol(b, LBound(b), UBound(b), ColTri)
FiltreMultiCol2 = b
End If
End Function |
Partager