Bonjour,
Je sais un peu près comment fonctionne une macro de tri sur une colonne pour une ligne entière mais seulement dans l'ordre alphabétique. Dans un nouveau tableau j'ai besoin de trier des lignes selon une colonne Matin/Soir/Nuit/WE, du coup j'aimerais savoir s'il est possible dans le code VBA d'indiquer cet ordre.
Voici la macro avec laquelle je fonctionne jusqu'à aujourd'hui :
Feuille :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
Call Tri
End If
End Sub
Module :
Sub Tri()
Dim LastRow As Long
LastRow = ActiveSheet.Range("B4").End(xlDown).Row
Range("A4:AM21" & LastRow).Sort Key1:=Range("B4"), Order1:=xlAscending, Key2:=Range("B5"), Order2:=xlAscending, Key3:=Range("B6"), Order3:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal
End Sub
J'ai essayé d'affecter key1 à matin, key2 à soir, key3 à nuit et key4 à WE mais ça ne marche pas.
Merci d'avance pour votre aide!