Vba Excel : fonction de tri ne marche pas
Résolu
arzawe
Messages postés
70
Date d'inscription
Statut
Membre
Dernière intervention
-
arzawe Messages postés 70 Date d'inscription Statut Membre Dernière intervention -
arzawe Messages postés 70 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Voici le code que j'ai créé pour trier des lignes dans une table Excel.
Lign correspond au nombre total de lignes de ma table.
xlApp.Range("A1:AK"&Lign).Sort(Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Header:=xlGuess,OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal)
Le problème est que, avant même d'exécuter la macro, il me dit que la syntaxe n'est pas bonne : il manquerait un =. Par contre, je ne vois pas où. Quelle est l'erreur de mon code ?
Merci d'avance
Voici le code que j'ai créé pour trier des lignes dans une table Excel.
Lign correspond au nombre total de lignes de ma table.
xlApp.Range("A1:AK"&Lign).Sort(Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("C1"), Order2:=xlAscending, _
Key3:=Range("D1"), Order3:=xlAscending, _
Header:=xlGuess,OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal)
Le problème est que, avant même d'exécuter la macro, il me dit que la syntaxe n'est pas bonne : il manquerait un =. Par contre, je ne vois pas où. Quelle est l'erreur de mon code ?
Merci d'avance
1 réponse
essaye avec cette formulation :
Range("A1:AK" & Lign).Sort Key1:=Range("B1"), Order1:=xlAscending, Key2:=Range("C1") _
, Order2:=xlAscending, Key3:=Range("D1"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
bonne journée.
Range("A1:AK" & Lign).Sort Key1:=Range("B1"), Order1:=xlAscending, Key2:=Range("C1") _
, Order2:=xlAscending, Key3:=Range("D1"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
bonne journée.
J'ai essayé la formulation suivante :
xlApp.range("A2:AK" & Lign).Select
Selection.Sort _
Key1:=range("B1"), Order1:=xlAscending, _
Key2:=range("C1"), Order2:=xlAscending, _
Key3:=range("D1"), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Et ça marche.
Ce qui m'ennuie, c'est de passer par le .Select
Je trouve que ça ne fait pas très "propre". J'aurais voulu passer la commande en direct.