Private Sub Worksheet_Change(ByVal Target As Range)
Dim Code$, Rang As Byte, N°$, N°Col As Byte, DerLgn As Long, PlageCible As Range
'Vérification cellule concernée :
'1) Validation
On Error Resume Next
With Target.Validation
Typ = .Type
form = .Formula1
End With
On Error GoTo 0
'2) Une seule cellule, Colonne E ou J, ligne entre 4 et 19, validation type liste avec la formule =Chx_Code
If (Target.Count = 1) And (Target.Column = 5 Or Target.Column = 10) And (Target.Row >= 4 And Target.Row <= 19) And (Typ = 3) And (form = "=Chx_Code") Then
With Target
Code = .Value
Rang = .Offset(0, -4).Value
N° = .Offset(0, -3).Value
N°Col = .Offset(0, -2).Value + 5
End With
'Vérification ligne renseignée
If Rang <> 0 And N° <> "" And N°Col <> 5 Then
With Feuil1
DerLgn = .Cells(.Rows.Count, 1).End(xlUp).Row
Set PlageCible = .Range(.Cells(2, 1), .Cells(DerLgn, 8))
End With
PlageCible.Cells(Rang, N°Col) = Code
End If
End If
End Sub