Private Sub Worksheet_Change(ByVal Cible As Range)
Dim ligne&, i&, a, b, c&, CelA As Range, CelB As Range, Plg As Range, x
Set Plg = Range("E3:E4") '*** Paramètres de recherche ***
If Not Intersect(Cible, Plg) Is Nothing Then
Set CelA = Range("B5") '*** Cellule d'intitulé des résultats ***
ligne = CelA.Row + 1
a = Plg(1).Value
b = Plg(2).Value
With Application: .ScreenUpdating = False: .EnableEvents = False: .Calculation = xlCalculationManual: End With
With Range(CelA, Cells(Rows.Count, CelA.Column).End(xlUp))
If .Rows.Count > 1 Then .Resize(.Rows.Count - 1, 1).Offset(1).ClearContents
End With
With Sheets("test3") '*** Feuille de données ***
Set CelB = .Range("C5") '*** Haut gauche de la plage de données ***
c = CelB.Row + 1
For i = CelB.Column To .Cells(c - 1, .Columns.Count).End(xlToLeft).Column
If .Cells(c - 1, i).Value = b And .Cells(c, i).Value = a Then
Set Plg = .Range(.Cells(c, i), .Cells(oMax(c - 1, .Cells(.Rows.Count, i).End(xlUp).Row), i))
If Plg.Rows.Count > 1 Then
If Not IsEmpty(Plg(2)) Then
Set Plg = Plg.Resize(Plg.Rows.Count - 1, 1).Offset(1)
Cells(ligne, CelA.Column).Resize(Plg.Rows.Count, 1).Value = Plg.Value
ligne = ligne + Plg.Rows.Count
End If
End If
End If
Next i
End With
With Application: .Calculation = xlCalculationAutomatic: .EnableEvents = True: .ScreenUpdating = True: End With
End If
End Sub
Private Function oMax(x&, y&)
oMax = ((x + y) + Abs(x - y)) / 2
End Function