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 46
| Option Explicit
Option Base 1
Sub SupprimeDoublons()
Dim Plage As Range, Cell As Range
Dim Un As New Collection
Dim Tableau() As Integer
Dim x As Integer
Dim derLi As Long
derLi = Sheets("prestation").Columns(5).Find("*", , , , , xlPrevious).Row
'derLi = Columns(5).Find("J", "P", "Y", "S", "C", "M", xlPrevious).Row
'Définit la plage de cellules pour la recherche de doublons
Set Plage = Worksheets("prestation").Range("E1:E19043" & derLi)
'Boucle sur les cellules de la plage cible
For Each Cell In Plage
On Error Resume Next
'Création d'une collection de données uniques (sans doublons)
Un.Add Cell, CStr(Cell)
'Une erreur survient si l'élément existe dans la collection.
'La procédure enregistre le numéro de ligne correspondant dans un tableau.
If Err.Number <> 0 Then
x = x + 1
ReDim Preserve Tableau(1 To x)
Tableau(x) = Cell.Row
End If
On Error GoTo 0
Next Cell
'On sort si aucun doublon n'a été trouvé.
If x = 0 Then Exit Sub
'Fige l'écran pendant la suppression des lignes
Application.ScreenUpdating = False
'Boucle sur le tableau pour supprimer les lignes contenant des doublons.
For x = UBound(Tableau) To LBound(Tableau) Step -1
Worksheets("prestation").Rows(Tableau(x)).EntireRow.Delete
Next x
Application.ScreenUpdating = True
End Sub |
Partager