Private Sub Worksheet_Activate()
Dim critere$, P As Range, ncol%, col%, a$(), n%
critere = "*merci*"
Set P = Sheets("Feuil2").UsedRange
ncol = P.Columns.Count
For col = 1 To ncol
If Application.CountIf(P.Columns(col), critere) Then
ReDim Preserve a(n) 'base 0
a(n) = P(1, col)
n = n + 1
End If
Next
If n Then tri a, 0, n - 1
'---restitution---
If FilterMode Then ShowAllData 'si la feuille est filtrée
With [A2] '1ère cellule de destination
If n Then .Resize(n) = Application.Transpose(a) 'Transpose est limitée à 65536 lignes
.Offset(n).Resize(Rows.Count - n - .Row + 1).ClearContents 'RAZ en dessous
End With
End Sub
Sub tri(a, gauc, droi) ' Quick sort
Dim ref, g, d, temp
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub