1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
Sub SuppressionDesDoublons(LigneTitre As Long, ColonneATester As Long, ColonneDoublons As Long)
Dim DerniereLigne As Long
DerniereLigne = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
' Tri
Range(Cells(LigneTitre, ColonneATester), Cells(DerniereLigne, ColonneATester)).Select
Selection.Sort Key1:=Cells(LigneTitre, ColonneATester), Order1:=xlDescending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
'-------------------------------------------------------
' Mise en place de la formule pour détecter les doublons
'-------------------------------------------------------
Cells(LigneTitre + 1, ColonneDoublons).FormulaR1C1 = "=IF(RC[" & ColonneATester - ColonneDoublons & "]=R[-1]C[" & ColonneATester - ColonneDoublons & "],""Oui"","""")"
Range(Cells(LigneTitre + 1, ColonneDoublons), Cells(DerniereLigne, ColonneDoublons)).Select
With Selection
.FillDown
.Copy
.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
'-------------------------
' Suppression des doublons
'-------------------------
' Range(Cells(LigneTitre + 1, ColonneDoublons), Cells(DerniereLigne, ColonneDoublons)).Select
For Each Cellule In Selection
If Cellule.Value = "Oui" Then Cellule.Offset(0, ColonneATester - ColonneDoublons).ClearContents
Next Cellule
'-----------------------------------
' Tri des lignes par ordre croissant
'-----------------------------------
Range(Cells(LigneTitre, ColonneATester), Cells(DerniereLigne, ColonneATester)).Select
Selection.Sort Key1:=Cells(LigneTitre, ColonneATester), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
' Suppression des enregistrements dans la colonne Doublons
Range(Cells(LigneTitre + 1, ColonneDoublons), Cells(DerniereLigne, ColonneDoublons)).ClearContents
End Sub |
Partager