Dim plage As Range 'mémorise la variable
Private Sub CommandButton1_Click()
Set plage = Intersect(Rows("3:65536"), UsedRange)
If plage Is Nothing Then Exit Sub
Copie "Feuil2", 2
Copie "Feuil3", 1
End Sub
Sub Copie(F$, col As Byte)
Dim ligne As Long, lig As Long, sup As Range
With Sheets(F)
ligne = .UsedRange.Row + .UsedRange.Rows.Count
plage.EntireRow.Copy .Rows(ligne)
.UsedRange = .UsedRange.Value 'supprime les formules
[COLOR="Red"].Rows("3:65536").Sort Key1:=.Columns(col), Order1:=xlDescending, Header:=xlNo 'tri sur la colonne des alertes
lig = Application.CountIf(.Columns(col), "Alerte!") + 3 '1ère ligne sans alerte
.Rows(lig & ":65536").Delete 'supprime les lignes sans alerte[/COLOR]
.Rows("3:65536").Sort Key1:=.Columns("D"), Header:=xlNo 'tri sur IMMAT
For lig = 4 To lig - 1
If .Cells(lig, "D") = .Cells(lig - 1, "D") Then _
[COLOR="Red"]Set sup = Union(.Rows(lig), IIf(sup Is Nothing, .Rows(lig), sup))[/COLOR] 'les commentaires éventuels en AB:AE sont sur la ligne précédente, et seront donc conservés
Next
If Not sup Is Nothing Then sup.Delete 'supprime les doublons
.Rows("3:65536").Sort Key1:=.Columns("I"), Order1:=xlAscending, Header:=xlNo 'tri sur dates MINES
End With
End Sub