Sub copie_decal()
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim Tablo As ListObject
Dim A As String, B As String, D As String, Semaine As String, Chantier As String
With Sheets("2022") 'dans la feuille 2022
A = MsgBox("Voulez-vouis saisir un nouveau chantier ?", vbYesNo + vbQuestion)
If A = vbNo Then
Close A
Else
Set Tablo = ActiveSheet.ListObjects(1)
With Tablo
lastCol = .ListColumns.Count
LastLine = .ListRows.Count
PointInsertion = LastLine - 4
For i = 1 To 6
.ListRows.Add PointInsertion
Next i
.Range(7, 1).Resize(5, 1).Copy Destination:=.Range(PointInsertion + 1, 1)
DebFor = 11
finfor = PointInsertion + 9
formule = "=MAX(0,G6-sumif($F$11:$F$" & finfor & ",SUBSTITUTE([@Semaines],""restantes "","""") &""sur chantier"",G$11:G$" & finfor & "))"
LastLine = .ListRows.Count
.Range(LastLine - 3, 2).Resize(4, lastCol - 1).Formula = formule
B = InputBox("Quel est le chantier ?", "Nom du chantier", "Nom du chantier")
If B = "Nom du chantier" Or B = " " Or B = "" Then
MsgBox "Veuillez entrez un nom de chantier", vbExclamation
Else
Semaine = InputBox("Quelle est la semaine concernée ?", vbOKCancel)
If Semaine < 0 Or Semaine > 52 Then
MsgBox "Veuillez entrer un nombre entre 1 et 52", vbExclamation
Else
BE = InputBox("Combien de temps de travail au BE ?", vbOKCancel)
Fab = InputBox("Combien de temps de travail pour la fabrication ?", vbOKCancel)
Fini = InputBox("Combien de temps de travail pour la finition ?", vbOKCancel)
Pose = InputBox("Combien de temps de travail pour la pose ?", vbOKCancel)
Cells(finfor - 4, Semaine + 6) = "- " & B ' + 6 car il y a 6 colonnes avant les colonnes des semaines
Cells(finfor - 3, Semaine + 6) = BE ' + 6 car il y a 6 colonnes avant les colonnes des semaines
Cells(finfor - 2, Semaine + 6) = Fab ' + 6 car il y a 6 colonnes avant les colonnes des semaines
Cells(finfor - 1, Semaine + 6) = Fini ' + 6 car il y a 6 colonnes avant les colonnes des semaines
Cells(finfor, Semaine + 6) = Pose ' + 6 car il y a 6 colonnes avant les colonnes des semaines
AutoColumnLength Cells(finfor - 4, Semaine + 6) ' + 6 car il y a 6 colonnes avant les colonnes des semaines
MsgBox "Le chantier " & B & " est crée", vbInformation, "Nom du chantier"
End If
End If
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End With
End Sub