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 test()
Dim MyRange As Range
Dim Feuille As Worksheet
Dim lig As Long
Dim Doublon As New Collection
Set Feuille = ActiveWorkbook.Sheets(1)
Set MyRange = Feuille.UsedRange
For lig = 2 To MyRange.Rows.Count
TrouveDoublon lig, Feuille, Doublon
DoEvents
Next
End Sub
Sub TrouveDoublon(lig As Long, Feuille As Worksheet, Doublon As Collection)
ReDim element(nbnodes) As Variant
Dim MyRange As Range
Dim elm
If MethodeHighlander(Feuille.Range(Feuille.Cells(lig, 1).Address & "," & Feuille.Cells(lig, 2).Address & "," & Feuille.Cells(lig, 3).Address), Doublon) = True Then
Feuille.Range(Feuille.Cells(lig, 1), Feuille.Cells(lig, Feuille.UsedRange.Columns.Count)).Interior.ColorIndex = 4
Else
'????? stocker_elm elm, el, lig
End If
End Sub
Function MethodeHighlander(MyRange As Range, Doublon As Collection) As Boolean
'La Méthode Highlander il ne peut en rester qu'un.
Dim Cels As Integer
Dim Text As String
Text = "T"
For Cels = 1 To MyRange.Count
Text = Text & "_" & Trim("" & MyRange(1, Cels))
Next
On Error Resume Next
'On peut ajouter dans une collection un enregistrement en lui donnant un nom.
'Le problème est qu'elle ne supporte pas les doublons.
'On utilise les messages d'erreur pour définir les doublons.
Doublon.Add txt, Text
If Err <> 0 Then
MethodeHighlander = True
Err.Clear
End If
On Error GoTo 0
End Function |
Partager