Vba Excel : fonction de tri ne marche pas

Résolu
arzawe Messages postés 71 Statut Membre -  
arzawe Messages postés 71 Statut Membre -
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
--

Arzawe
Configuration: Windows XP
Internet Explorer 6.0

1 réponse

  1. LePierre Messages postés 249 Statut Membre 338
     
    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
    1. arzawe Messages postés 71 Statut Membre 5
       
      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