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 52 53 54 55
|
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
'Definir quelle feuille
Set f = ActiveSheet
'Definir quelle region de cette feuille
Set tout = f.Range("B3:E" & f.Rows.Count)
'Definir quelle ligne de cette region
Set cetteligne = Intersect(tout, f.Rows(Target.Row))
If cetteligne Is Nothing Then Exit Sub
'Est-ce que Target est dans cetteligne
If Intersect(cetteligne, Target) Is Nothing Then Exit Sub
'Recherche sur cette ligne
Methode = 1
If Methode = 1 Then
'Methode 1 : Rechercher doublon avec For...Next
Set rng = Nothing
For k = 1 To cetteligne.Columns.Count
If cetteligne.Cells(1, k).Value = Target.Value Then
If Intersect(cetteligne.Cells(1, k), Target) Is Nothing Then
Set rng = cetteligne.Cells(1, k)
Exit For
End If
End If
Next
Else
'Methode 2 : Rechercher doublon avec FIND et LookIn:=xlFormulas
Set rng = cetteligne.Find(what:=Target.Value, After:=Target, LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchFormat:=False, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
End If
If rng Is Nothing Then Exit Sub
If rng.Address = Target.Address Then
'Pas de doublon
Else
MsgBox "Doublon en " & rng.Address
End If
End Sub |