Sub TrierCommentaires()
'se lance par Ctrl+T
Dim r As Range, sep$, s, a(), i
Set r = [G:G] 'plage à adapter
sep = vbLf & "- " 'séparateur à adapter
On Error Resume Next 'si aucun commentaire
Set r = r.SpecialCells(xlCellTypeComments)
On Error GoTo 0
If r Is Nothing Then Exit Sub
For Each r In r
s = Split(r.Comment.Text, sep)
If UBound(s) > 1 Then
ReDim a(UBound(s) - 1)
For i = 0 To UBound(a)
If IsNumeric(s(i + 1)) Then a(i) = CDbl(s(i + 1)) Else a(i) = s(i + 1)
Next
tri a, 0, UBound(a)
r.Comment.Text s(0) & sep & Join(a, sep)
r.Comment.Shape.TextFrame.Characters(Len(s(0)) + 1).Font.Bold = False 'non gras
End If
Next
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