Private Sub Worksheet_Change(ByVal Target As Range)
Dim lgDerCol As Long
Dim lgCol As Long
Dim lgDerLig As Long
Dim lgLig As Long
Dim lgLigC As Long
If Not Intersect(Target, Range("D9")) Is Nothing And Target.Count = 1 Then
' Effacer le contenu des lignes 14 à 28
Range("C14:F28").ClearContents
lgLigC = 14
With Worksheets("Ambazac")
' Rechercher la colonne du nom dans la feuille Ambazac
lgDerCol = .Cells(2, .Cells.Columns.Count).End(xlToLeft).Column
For lgCol = 7 To lgDerCol
' Le nom est trouvé
If .Cells(2, lgCol).Value = Range("D9").Value Then
' Rechercher les lignes ayant un X dans la colonne du nom
lgDerLig = .Range("A" & .Cells.Rows.Count).End(xlUp).Row
For lgLig = 3 To lgDerLig
' La ligne comporte un X dans la colonne
If .Cells(lgLig, lgCol) = "X" Then
Range("C" & lgLigC).Value = .Range("A" & lgLig).Value
lgLigC = lgLigC + 1
End If
Next lgLig
End If
Next lgCol
End With
'Teste si la feuille rajoutée existe déjà
If FeuilExist(Range("d9").Value) = False Then
Sheets("AUTORISATION").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = Range("d9").Value
Sheets("AUTORISATION").Activate
Exit Sub
Else
MsgBox "la Feuille " & Range("d9").Value & " existe déjà" & vbCrLf & "Changer le Nom SVP", , "Attention :"
End If
End If
End Sub