[Question -VBA] - Trier sur 2 colonnes avec 2 CustomOrder

Bonjour,

Lorsque je veux trier sur 2 colonnes, avec des ordres particuliers, je m'y prend ainsi :

'With ActiveSheet
'lras = .Cells(.Rows.Count, habnat).End(xlUp).Row: lcas = .Cells(1, .Columns.Count).End(xlToLeft).Column
'        .Sort.SortFields.clear
'        .Sort.SortFields.Add2 Key:=.Range(.Cells(2, enj), .Cells(lras, enj)), SortOn:=xlSortOnValues, _
'        Order:=xlAscending, CustomOrder:="Très fort,Fort,Modéré,Faible,Très faible,Nul, - ", DataOption:=xlSortNormal
'        .Sort.SortFields.Add2 Key:=.Range(.Cells(2, surf), .Cells(lras, surf)), SortOn:=xlSortOnValues, _
'        Order:=xlDescending, CustomOrder:="<0,01 ha", DataOption:=xlSortNormal

'        Set plg = .Range(.Cells(1, 1), .Cells(lras, lcas))
'            With ActiveSheet.Sort
'                .SetRange plg
'                .Header = xlYes
'                .MatchCase = False
'                .Orientation = xlTopToBottom
'                .SortMethod = xlPinYin
'                .Apply
'            End With
'    End If
'End With

Et ça fonctionne.

J'ai voulu faire quelque chose de plus simple, en utilisant pas de range.

Sans CustomOrder, ça fonctionne (mais ça ne classe pas dans l'ordre que je veux bien entendu) :

With ActiveSheet
lras = .Cells(.Rows.Count, 1).End(xlUp).Row: lcas = .Cells(1, .Columns.Count).End(xlToLeft).Column
    .Range(.Cells(1, 1), .Cells(lras, lcas)).Sort _
        Key1:=Range(.Cells(1, enj), .Cells(lras, enj)), Order1:=xlAscending, DataOption1:=xlSortNormal, _
        Key2:=Range(.Cells(1, surf), .Cells(lras, surf)), order2:=xlAscending, DataOption2:=xlSortNormal, Header:=xlYes
End With

En revanche, si je m'y prend ainsi :

With ActiveSheet
lras = .Cells(.Rows.Count, 1).End(xlUp).Row: lcas = .Cells(1, .Columns.Count).End(xlToLeft).Column
    .Range(.Cells(1, 1), .Cells(lras, lcas)).Sort _
        Key1:=Range(.Cells(1, enj), .Cells(lras, enj)), Order1:=xlAscending, CustomOrder1:="Très fort,Fort,Modéré,Faible,Très faible,Nul, - ", DataOption1:=xlSortNormal, _
        Key2:=Range(.Cells(1, surf), .Cells(lras, surf)), order2:=xlAscending, CustomOrder2:="<0,01 ha", DataOption2:=xlSortNormal, Header:=xlYes
End With

J'ai une erreur d'exécution (erreur définie par l'application ou par l'objet).

Ma question est : Est-ce que je m'y prend mal, ou alors on ne peut simplement pas faire de cette manière ?

Bonne journée !

Bonjour,

Apparemment la méthode Range.Sort n'a pas de paramètre CustomeOrder !

Tu dois penser à regarder l'aide Excel (F1).

Cdlt.

D'accord, merci !

En effet, je n'avais pas regardé l'aide Excel.

Rechercher des sujets similaires à "question vba trier colonnes customorder"