Microsoft 365 Trier de A à Z

Gourbi1986

XLDnaute Nouveau
Bonjour à tous,

J'ai un souci, dans le fichier que j'ai joint je n'arrive pas à conserver l'ordre de mes données dans la colonne, quand j'utilise la fonction trier de A à Z.
Pourriez-vous m'aider svp ?

Merci pour votre soutien.
 

Pièces jointes

  • Test A à Z.xlsx
    18.2 KB · Affichages: 29

job75

XLDnaute Barbatruc
Bonjour le fil, le forum,

S'il y a plus de 3 niveaux de hiérarchisation il faut une autre méthode pour trier , fichier(4) :
VB:
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
A+
 

Pièces jointes

  • Test A à Z(4).xlsm
    41.7 KB · Affichages: 5

Discussions similaires

Réponses
10
Affichages
432
Réponses
8
Affichages
266

Statistiques des forums

Discussions
312 836
Messages
2 092 640
Membres
105 476
dernier inscrit
hilt