P
psycho
Guest
Bonjour le forum,
Après 5 ans sans question, en voici une puisque j'ai fait un stage VBA je peux enfin mettre les mains dedans en comprenant ce que je fait 🙂
Une recherche sur le forum n'a rien donné, voici mon souci :
Mon code VBA pour faire un tri personnalisé (3 colonnes à trier), ne trie pas complètement, contrairement à l'outil d'excel.
J'ai généré le code avec l'enregistreur de macro et je l'ai adapté.
Voila le code que donne l'enregistreur :
et voila mon adapatation
Si quelqu'un à une idée, merci d'avance.
Après 5 ans sans question, en voici une puisque j'ai fait un stage VBA je peux enfin mettre les mains dedans en comprenant ce que je fait 🙂
Une recherche sur le forum n'a rien donné, voici mon souci :
Mon code VBA pour faire un tri personnalisé (3 colonnes à trier), ne trie pas complètement, contrairement à l'outil d'excel.
J'ai généré le code avec l'enregistreur de macro et je l'ai adapté.
Voila le code que donne l'enregistreur :
Code:
ActiveWorkbook.Worksheets("2010").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("2010").Sort.SortFields.Add Key:=Range("A3:A45"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("2010").Sort.SortFields.Add Key:=Range("B3:B45"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("2010").Sort.SortFields.Add Key:=Range("E3:E45"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("2010").Sort
.SetRange Range("A2:FN45")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
et voila mon adapatation
Code:
Sub test()
Dim PLAGE As Range
Dim JOURS As Range
Dim VILLE As Range
Dim CONDUC As Range
'Définition des plages
Set PLAGE = ActiveSheet.Range("A2").CurrentRegion
Set PLAGE = PLAGE.Offset(1).Resize(PLAGE.Rows.Count - 1)
ActiveSheet.Range("A3").Select
Set JOURS = Range(Selection, Selection.End(xlDown))
ActiveSheet.Range("B3").Select
Set VILLE = Range(Selection, Selection.End(xlDown))
ActiveSheet.Range("E3").Select
Set CONDUC = Range(Selection, Selection.End(xlDown))
'Tri personnalisé
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("A" & JOURS.Cells(1) & ":A" & JOURS.Cells.Count), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveSheet.Sort.SortFields.Add Key:=Range("A" & VILLE.Cells.Count + 1 - VILLE.Cells.Count & ":A" & VILLE.Cells.Count), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveSheet.Sort.SortFields.Add Key:=Range("A" & CONDUC.Cells.Count + 1 - CONDUC.Cells.Count & ":A" & CONDUC.Cells.Count), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("A2:FN45")
.Header = xlYes
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A2").Select
End Sub
Si quelqu'un à une idée, merci d'avance.