Vba Excel : fonction de tri ne marche pas

Résolu/Fermé
arzawe Messages postés 70 Date d'inscription mardi 24 août 2004 Statut Membre Dernière intervention 14 septembre 2014 - 18 mars 2008 à 10:28
arzawe Messages postés 70 Date d'inscription mardi 24 août 2004 Statut Membre Dernière intervention 14 septembre 2014 - 19 mars 2008 à 11:51
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

1 réponse

LePierre Messages postés 249 Date d'inscription samedi 8 mars 2008 Statut Membre Dernière intervention 2 août 2012 337
18 mars 2008 à 17:53
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.
0
arzawe Messages postés 70 Date d'inscription mardi 24 août 2004 Statut Membre Dernière intervention 14 septembre 2014 5
19 mars 2008 à 11:51
Je te remercie de ton aide, mais il n'est pas d'accord pour cette commande.
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.
0