Option Explicit
Sub TriParMois()
'
Dim derLi As Long
Dim M As String
Application.ScreenUpdating = False
'Recherche de la dernière ligne de la colonne A
derLi = Columns("A").Find("*", , , , , xlPrevious).Row
Range("A2:K" & derLi).Interior.ColorIndex = xlNone 'A1 a adapter
RedoM:
'Choix du mois
M = Application.InputBox("Choisissez le mois", "", Month(Date), , , , , 1)
If M = "0" Then GoTo RedoM
If M = False Then GoTo Fin2
If M > 12 Or M < 1 Then GoTo RedoM
'Insertion d'une colonne temporaire
Columns("I:I").Insert Shift:=xlToRight
'Inscription de la formule pour trier par mois
Range("I2:I" & derLi).FormulaR1C1 = "=MONTH(RC[1])"
'Tri
ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Add Key:=Range("I2:I" & derLi), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Feuil1").Sort
.SetRange Range("A1:K" & derLi)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
'le filtre
ActiveSheet.Range("$A$1:$K$" & derLi).AutoFilter 9, Criteria1:=M
On Error GoTo Erreur
Range("A2:K" & derLi).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = 6
On Error GoTo 0: GoTo Fin
Erreur: MsgBox "Pas de correspondance pour ce mois."
Fin:
Selection.AutoFilter
'Suppression de la colonne temporaire
Columns("I").Delete Shift:=xlToLeft
Fin2: Application.ScreenUpdating = True
End Sub