Private Sub OptionButton1_Change()
Tri IIf(OptionButton1, xlAscending, xlDescending)
End Sub
Sub Tri(ordre%)
Dim T As Range, cc%, P As Range, col%
Set T = ListObjects(1).DataBodyRange 'tableau structuré
Application.ScreenUpdating = False
On Error Resume Next 'si aucune SpecialCell
cc = T.Columns.Count
With Workbooks.Add.Sheets(1) 'nouveau document
.[A:A].NumberFormat = "@" 'format Texte
.[A1].Resize(T.Rows.Count, cc) = T.Value
.[A:A].TextToColumns .Cells(1, cc + 1), xlDelimited, Other:=True, OtherChar:="." 'commande Convertir
Set P = .UsedRange
P.Columns(cc + 1).Resize(, P.Columns.Count - cc).SpecialCells(xlCellTypeBlanks) = 0 'pour que le classement soit correct
'---méthode de tri pour tous niveaux de hiérarchisation---
.Sort.SortFields.Clear
For col = cc + 1 To P.Columns.Count
.Sort.SortFields.Add Key:=P.Columns(col), SortOn:=xlSortOnValues, Order:=ordre
Next
With .Sort
.SetRange P
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
T.Columns(1).NumberFormat = "@" 'format Texte
T = P.Resize(, cc).Value 'restitution
T.Columns(1).NumberFormat = "General" 'format Standard
.Parent.Close False 'ferme le document
End With
Application.ScreenUpdating = True
End Sub