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 47 48 49 50 51
|
tx=split("TOTO;TITI;Cheval;Autruche")
if Highlander(Init, tx,"test", MyRange(L, 1),MyRange(L, 3), MyRange(L, 4), MyRange(L, 5))= True Then Msgbox "Doublon"
Function Highlander(Init As Boolean, ParamArray Plage()) As Boolean
'..................................................
'La méthode Highlander, il ne peut en rester qu'un.
'Retourne True si doublon.
'..................................................
Static CollectDoublon As Collection
Dim T As String
Dim PlageIndex As Long
Dim myPlage As Range
Dim Col As Integer
Dim Tableau
If Init = False Then
Init = True
Set CollectDoublon = Nothing
Set CollectDoublon = New Collection
End If
T = "T"
For PlageIndex = 0 To UBound(Plage)
If TypeName(Plage(PlageIndex)) = "Range" Then
Set myPlage = Plage(PlageIndex)
For Col = 1 To myPlage.Columns.Count
T = T & "_" & Trim("" & myPlage(1, Col))
Next
Else
If TypeName(Plage(PlageIndex)) = "Variant()" Then
Tableau = Plage(PlageIndex)
Else
If TypeName(Plage(PlageIndex)) Like "*()" Then
Tableau = Plage(PlageIndex)
Else
Tableau = Split(Plage(PlageIndex) & ";", ";")
End If
End If
For Col = 0 To UBound(Tableau)
If Trim("" & Tableau(Col)) <> "" Then T = T & "_" & Trim("" & Tableau(Col))
Next
End If
Next
On Error Resume Next
CollectDoublon.Add T, T
If Err <> 0 Then Highlander = True
On Error GoTo 0
End Function |
Partager