Private Sub Worksheet_Change(ByVal Target As Range)
Dim lig&
If Intersect(Target, [D4:D5]) Is Nothing Or IsEmpty([D5]) Then Exit Sub
If Not Intersect(Target, [D4]) Is Nothing Then [D5] = "": Exit Sub
If IsEmpty([D4]) Then MsgBox "Indiquez d'abord le nom...": _
[D5] = "": [D4].Select: Exit Sub
With Feuil2 'CodeName
If Application.CountIf(.[C:C], [D5]) Then MsgBox "Code déjà enregistré...": _
[D5] = "": [D5].Select: Exit Sub
lig = .[A65536].End(xlUp).Row + 1
.Cells(lig, 1) = Date
.Cells(lig, 2) = [D4]
.Cells(lig, 3) = [D5]
.[A:C].Sort .[B1], xlAscending, Header:=xlYes 'tri sur les noms
End With
End Sub