XL 2019 Trie par Niveaux

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

la colonne Série c'est la cellule F1
la colonne Poste c'est la cellule G1
ajouter ces deux clé dans l'ordre de pour faire le tri par Série et après par Poste pour les lignes ayant la même série
VB:
    With Worksheets("Fiche planning tir24-25").Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("F1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .SortFields.Add Key:=Range("G1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin

        .SetRange Worksheets("Fiche planning tir24-25").UsedRange
        
        .Apply
    End With
 
la colonne Série c'est la cellule F1
la colonne Poste c'est la cellule G1
ajouter ces deux clé dans l'ordre de pour faire le tri par Série et après par Poste pour les lignes ayant la même série
VB:
    With Worksheets("Fiche planning tir24-25").Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("F1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .SortFields.Add Key:=Range("G1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin

        .SetRange Worksheets("Fiche planning tir24-25").UsedRange
       
        .Apply
    End With
merci
 
Bonjour,
Une autre proposition. Les données sont sous forme de tableau structuré.
Cdlt.

VB:
Public Sub SortData()
Dim TD As Range

    Set TD = Range("T_Planning")
    
    If TD.ListObject.DataBodyRange Is Nothing = False Then
        With TD.ListObject.Sort
            .SortFields.Clear
            .SortFields.Add Key:=TD(0, 6)
            .SortFields.Add Key:=TD(0, 7)
            .Header = xlYes
            .Apply
        End With
    End If
    
    Set TD = Nothing
    
End Sub
 

Pièces jointes

Bonjour,
Une autre proposition. Les données sont sous forme de tableau structuré.
Cdlt.

VB:
Public Sub SortData()
Dim TD As Range

    Set TD = Range("T_Planning")
   
    If TD.ListObject.DataBodyRange Is Nothing = False Then
        With TD.ListObject.Sort
            .SortFields.Clear
            .SortFields.Add Key:=TD(0, 6)
            .SortFields.Add Key:=TD(0, 7)
            .Header = xlYes
            .Apply
        End With
    End If
   
    Set TD = Nothing
   
End Sub
 
Bonjour,
Une autre proposition. Les données sont sous forme de tableau structuré.
Cdlt.

VB:
Public Sub SortData()
Dim TD As Range

    Set TD = Range("T_Planning")
   
    If TD.ListObject.DataBodyRange Is Nothing = False Then
        With TD.ListObject.Sort
            .SortFields.Clear
            .SortFields.Add Key:=TD(0, 6)
            .SortFields.Add Key:=TD(0, 7)
            .Header = xlYes
            .Apply
        End With
    End If
   
    Set TD = Nothing
   
End Sub
merci beaucoup
tres bien
 
Bonjour à tous,
Pour aller dans la même direction que @Jean-Eric ,
Si le tri cible une Ts, on peut indiquer les colonnes "en clair" pour plus de lisibilité :
VB:
Public Sub SortData()
    With [T_Planning].ListObject.Sort
        .SortFields.Clear
        .SortFields.Add Key:=[T_Planning[Série]]
        .SortFields.Add Key:=[T_Planning[Poste]]
        .Header = xlYes
        .Apply
    End With
End Sub

Ceci permet également de déplacer une colonne sans perturber le code .
Par contre, ne pas renommer les colonnes ... sinon utiliser l'autre code 🤗
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
5
Affichages
103
Réponses
3
Affichages
130
Réponses
1
Affichages
115
  • Question Question
XL 2021 listbox
Réponses
18
Affichages
284
  • Question Question
Microsoft 365 formule countif
Réponses
5
Affichages
478
Retour