Option Explicit
Sub test()
Dim x, e, n As Long
Sheets("Feuil3").Rows("1:5").ClearContents
With Sheets("Feuil1").Range("e7").CurrentRegion
For Each e In Array(Array("M", "a1"), Array("F", "e1"))
x = Filter(.Parent.Evaluate("transpose(if(" & .Columns(3).Address & _
"=""" & e(0) & """,row(1:" & .Rows.Count & "),char(2)))"), Chr(2), 0)
n = UBound(x)
If n > -1 Then
x = Application.Index(.Value2, Application.Transpose(x), [{1,2,3}])
If n > 0 Then
n = UBound(x, 1)
mySort x, LBound(x, 1), n, 2
Else: n = 1
End If
'restitution
With Sheets("Feuil3").Range(e(1))
.Offset(, 1).Resize(5).NumberFormat = "dd/mm/yyyy"
If n = 1 Then
.Resize(n, UBound(x)).Value = x
Else
If n < 5 Then
.Resize(n, UBound(x, 2)).Value = x
Else
.Resize(5, UBound(x, 2)).Value = x
End If
End If
End With
End If
Next
End With
End Sub
Private Sub mySort(a, LB As Long, UB As Long, ref As Long)
Dim i As Long, ii As Long, iii As Long, temp
For i = LB To UB - 1
For ii = i + 1 To UB
If a(i, ref) > a(ii, ref) Then
For iii = LBound(a, 2) To UBound(a, 2)
temp = a(i, iii): a(i, iii) = a(ii, iii): a(ii, iii) = temp
Next
End If
Next
Next
End Sub