Option Compare Text 'la casse est ignotée
Private Sub Worksheet_Activate()
Dim critere$, P As Range, nlig&, j%, a$(), b$(), i&, n%
critere = "*merci*"
Set P = Sheets("Feuil2").UsedRange
nlig = P.Rows.Count
For j = 1 To P.Columns.Count
If Application.CountIf(P.Columns(j), critere) Then
ReDim Preserve a(n) 'base 0
ReDim Preserve b(n) 'base 0
a(n) = P(1, j)
For i = 2 To nlig
If P(i, j) Like critere Then b(n) = b(n) & vbLf & P(i, j)
Next i
b(n) = Mid(b(n), 2) 'supprime le 1er vbLf
n = n + 1
End If
Next j
'---restitution---
Application.ScreenUpdating = False
If FilterMode Then ShowAllData 'si la feuille est filtrée
With [A2] '1ère cellule de destination
.Resize(Rows.Count - .Row + 1).Clear 'RAZ
If n = 0 Then Exit Sub
.Resize(n) = Application.Transpose(a) 'Transpose est limitée à 65536 lignes
For i = 1 To n
.Cells(i).AddComment b(i - 1) 'crée un commentaire
With .Cells(i).Comment.Shape
.Width = 1000
.TextFrame.AutoSize = True 'ajustement largeur
End With
Next
.Resize(n).Sort .Cells, xlAscending, Header:=xlNo 'tri
End With
End Sub