Skip to content

Instantly share code, notes, and snippets.

@cyrilferte
Created December 6, 2016 12:55
Show Gist options
  • Save cyrilferte/fe3e755f3bb04d243e9f718bd38a4e38 to your computer and use it in GitHub Desktop.
Save cyrilferte/fe3e755f3bb04d243e9f718bd38a4e38 to your computer and use it in GitHub Desktop.
Sub Macroincertion()
'
' Macro d'ajout de cell
'
Dim groupCheck As String 'lettre du lot de travaux
Dim i As Integer
For i = 1 To 100
If Worksheets("Planning container").Range("A" & i).Value = "B" Then
lotBinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "C" Then
lotCinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "D" Then
lotDinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "E" Then
lotEinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "F" Then
lotFinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "G" Then
lotGinit = i
End If
Next
logGend = Worksheets("Planning container").Cells(Worksheets("Planning container").Rows.Count, "A").End(xlUp).Row
MsgBox (logGend)
'end loop i
groupNewTache = InputBox("lot de travaux ? (A, B, C...)", "ajout de tache")
nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")
If groupNewTache = "A" Then
Rows(lotBinit - 1).Insert
rowWrite = lotBinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "B" Then
Rows(lotCinit - 1).Insert
rowWrite = lotCinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "C" Then
Rows(lotDinit - 1).Insert
rowWrite = lotDinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "D" Then
Rows(lotEinit - 1).Insert
rowWrite = lotEinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "E" Then
Rows(lotFinit - 1).Insert
rowWrite = lotFinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "F" Then
Rows(lotGinit - 1).Insert
rowWrite = lotGinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "G" Then
Worksheets("Planning container").Range("B" & lotGend).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
Else
MsgBox ("mauvais nom de lot de travail")
End If
nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")
MsgBox (nomNewTache)
endOutils = False
While endOutils = False
addOutil = InputBox("nom de l'outil", "ajout d'outils")
nbOutil = InputBox("quantité ?", "ajout d'outils")
jOutil = InputBox("jour d'utilisation ?", "ajout d'outils")
jAproOutil = InputBox("jour d'aprovissionnement ?", "ajout d'outils")
lColumn = ws.Cells(rowWrite, Columns.Count).End(xlToLeft).Column
Worksheets("Détail des tâches").Range(lColumn & rowWrite).Value= addOutil
endInputOutils = InputBox("ajouter un autre outil ? (oui ou non)", "ajout de tache")
If endInputOutils = "non" Then
endOutils = True
End If
Wend
'ajout nom de tache
'planning B. OK
'semaine B
'detail outil OK
'addoutil
'semaine b
'detail e to infinite
'nbOutil
'semaine C
'jOutil
'planning B
'semaine B
'detail outil
'jAproOutil
'planning B
'semaine B
'detail outil
End Sub
@cyrilferte
Copy link
Author

Sub Macroincertion()
'
' Macro d'ajout de cell
'
Dim groupCheck As String 'lettre du lot de travaux
Dim i As Integer

For i = 1 To 100
If Worksheets("Planning container").Range("A" & i).Value = "B" Then

   lotBinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "C" Then
  
   lotCinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "D" Then
   
   lotDinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "E" Then
  
   lotEinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "F" Then
   
   lotFinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "G" Then
   
   lotGinit = i
End If

Next
logGend = Worksheets("Planning container").Cells(Worksheets("Planning container").Rows.Count, "A").End(xlUp).Row
MsgBox (logGend)
For i = 1 To 1000
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "B" Then

   lotBinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine1 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "B" Then

   lotBinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine2 = i
End If

Next

For i = 1 To 1000
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "B" Then

   lotBinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine3 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "B" Then

   lotBinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine4 = i
End If

Next

'end loop i

groupNewTache = InputBox("lot de travaux ? (A, B, C...)", "ajout de tache")
nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")

If groupNewTache = "A" Then
Worksheets("Planning container").Rows(lotBinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotBinit - 1).Insert
rowWrite = lotBinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "B" Then
Worksheets("Planning container").Rows(lotCinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotCinit - 1).Insert
rowWrite = lotCinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "C" Then
Worksheets("Planning container").Rows(lotDinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotDinit - 1).Insert
rowWrite = lotDinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "D" Then
Worksheets("Planning container").Rows(lotEinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotEinit - 1).Insert
rowWrite = lotEinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "E" Then
Worksheets("Planning container").Rows(lotFinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotFinit - 1).Insert
rowWrite = lotFinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "F" Then
Worksheets("Planning container").Rows(lotGinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotGinit - 1).Insert
rowWrite = lotGinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "G" Then
Worksheets("Planning container").Range("B" & lotGend).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
Else
MsgBox ("mauvais nom de lot de travail")
End If

nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")
MsgBox (nomNewTache)

endOutils = False

While endOutils = False

addOutil = InputBox("nom de l'outil", "ajout d'outils")
nbOutils = InputBox("quantité ?", "ajout d'outils")
jTache = InputBox("jour d'utilisation ?", "ajout d'outils")
jAproOutil = InputBox("jour d'aprovissionnement ?", "ajout d'outils")

nbDiffOutils = 0
Worksheets("Détail des tâches").Cells(rowWrite, 5 + nbDiffOutils).Value = addOutil
nbDiffOutils = nbDiffOutils + 1

Worksheets("Planning container").Cells(rowWrite, jTache + 2).Value = "x"
Worksheets("Détail des tâches").Cells(rowWrite, 3).Value = "j" + jTache
Worksheets("Détail des tâches").Cells(rowWrite, 4).Value = "j" + jAproOutil

'gestion des semaine
tacheInsert = False

If jAproOutil <= 5 Then
tacheInsert = True
If groupNewTache = "A" Then
Worksheets("Pièces semaine 1").Rows(lotBinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotBinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotBinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotBinitsemaine1).Value = nomNewTache
Worksheets("Pièces semaine 1").Range("C" & lotBinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotBinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5
ElseIf groupNewTache = "B" Then
Worksheets("Pièces semaine 1").Rows(lotCinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotCinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotCinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotCinitsemaine1).Value = nomNewTache
Worksheets("Pièces semaine 1").Range("C" & lotCinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotCinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5
ElseIf groupNewTache = "C" Then
Worksheets("Pièces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotDinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotDinitsemaine1).Value = nomNewTache
Worksheets("Pièces semaine 1").Range("C" & lotDinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotDinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5

ElseIf groupNewTache = "D" Then
Worksheets("Pièces semaine 1").Rows(lotEinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotEinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotEinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotEinitsemaine1).Value = nomNewTache
Worksheets("Pièces semaine 1").Range("C" & lotEinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotEinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5
ElseIf groupNewTache = "E" Then
Worksheets("Pièces semaine 1").Rows(lotFinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotFinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotFinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotFinitsemaine1).Value = nomNewTache
Worksheets("Pièces semaine 1").Range("C" & lotFinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotFinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5

ElseIf groupNewTache = "F" Then
Worksheets("Pièces semaine 1").Rows(lotGinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotGinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotGinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotGinitsemaine1).Value = nomNewTache
Worksheets("Pièces semaine 1").Range("C" & lotGinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotGinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5

ElseIf groupNewTache = "G" Then
Lastrowsemaine1 = Worksheets("Pièces semaine 1").Cells(Worksheets("Pièces semaine 1").Rows.Count, "B").End(xlUp).Row
Worksheets("Pièces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & Lastrowsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(Lastrowsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & Lastrowsemaine1).Value = nomNewTache
Worksheets("Pièces semaine 1").Range("C" & Lastrowsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(Lastrowsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5

Else
MsgBox ("mauvais nom de lot de travail")
End If

Worksheets("Pièces semaine 1").Rows(lotEinit - 1).Insert

ElseIf jAproOutil >= 6 And jAproOutil <= 10 Then

tacheInsert = True

ElseIf jAproOutil >= 11 And jAproOutil <= 15 Then

tacheInsert = True

ElseIf jAproOutil >= 16 And jAproOutil <= 20 Then

tacheInsert = True

Else
MsgBox ("mauvaise semaine")
End If

endInputOutils = InputBox("ajouter un autre outil ? (oui ou non)", "ajout de tache")
If endInputOutils = "non" Then
    endOutils = True
End If

j = j + 1

Wend

'ajout nom de tache
'planning B. OK
'semaine B
'detail outil OK
'addoutil
'semaine b
'detail e to infinite
'nbOutil
'semaine C
'jOutil
'planning B
'semaine B
'detail outil
'jAproOutil
'planning B
'semaine B
'detail outil

End Sub

@cyrilferte
Copy link
Author

Sub Macroincertion()
'
' Macro d'ajout de cell
'
Dim groupCheck As String 'lettre du lot de travaux
Dim i As Integer

For i = 1 To 100
If Worksheets("Planning container").Range("A" & i).Value = "B" Then

   lotBinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "C" Then
  
   lotCinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "D" Then
   
   lotDinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "E" Then
  
   lotEinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "F" Then
   
   lotFinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "G" Then
   
   lotGinit = i
End If

Next
logGend = Worksheets("Planning container").Cells(Worksheets("Planning container").Rows.Count, "A").End(xlUp).Row
MsgBox (logGend)
For i = 1 To 1000
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "B" Then

   lotBinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine1 = i
End If
If Worksheets("Pièces semaine 1").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine1 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "B" Then

   lotBinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine2 = i
End If
If Worksheets("Pièces semaine 2").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine2 = i
End If

Next

For i = 1 To 1000
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "B" Then

   lotBinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine3 = i
End If
If Worksheets("Pièces semaine 3").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine3 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "B" Then

   lotBinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine4 = i
End If
If Worksheets("Pièces semaine 4").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine4 = i
End If

Next

'end loop i

groupNewTache = InputBox("lot de travaux ? (A, B, C...)", "ajout de tache")
nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")

If groupNewTache = "A" Then
Worksheets("Planning container").Rows(lotBinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotBinit - 1).Insert
rowWrite = lotBinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "B" Then
Worksheets("Planning container").Rows(lotCinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotCinit - 1).Insert
rowWrite = lotCinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "C" Then
Worksheets("Planning container").Rows(lotDinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotDinit - 1).Insert
rowWrite = lotDinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "D" Then
Worksheets("Planning container").Rows(lotEinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotEinit - 1).Insert
rowWrite = lotEinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "E" Then
Worksheets("Planning container").Rows(lotFinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotFinit - 1).Insert
rowWrite = lotFinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "F" Then
Worksheets("Planning container").Rows(lotGinit - 1).Insert
Worksheets("Détail des tâches").Rows(lotGinit - 1).Insert
rowWrite = lotGinit - 2
Worksheets("Planning container").Range("B" & rowWrite).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
ElseIf groupNewTache = "G" Then
Worksheets("Planning container").Range("B" & lotGend).Value = nomNewTache
Worksheets("Détail des tâches").Range("B" & rowWrite).Value = nomNewTache
Else
MsgBox ("mauvais nom de lot de travail")
End If

nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")
MsgBox (nomNewTache)

endOutils = False

While endOutils = False

addOutil = InputBox("nom de l'outil", "ajout d'outils")
nbOutils = InputBox("quantité ?", "ajout d'outils")
jTache = InputBox("jour d'utilisation ?", "ajout d'outils")
jAproOutil = InputBox("jour d'aprovissionnement ?", "ajout d'outils")

nbDiffOutils = 0
Worksheets("Détail des tâches").Cells(rowWrite, 5 + nbDiffOutils).Value = addOutil
nbDiffOutils = nbDiffOutils + 1

Worksheets("Planning container").Cells(rowWrite, jTache + 2).Value = "x"
Worksheets("Détail des tâches").Cells(rowWrite, 3).Value = "j" + jTache
Worksheets("Détail des tâches").Cells(rowWrite, 4).Value = "j" + jAproOutil

'gestion des semaine
tacheInsert = False

If jAproOutil <= 5 Then

If groupNewTache = "A" Then
Worksheets("Pièces semaine 1").Rows(lotBinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotBinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotBinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotBinitsemaine1).Value = nomNewTache
tacheInsert = True
Worksheets("Pièces semaine 1").Range("C" & lotBinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotBinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5
ElseIf groupNewTache = "B" Then
Worksheets("Pièces semaine 1").Rows(lotCinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotCinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotCinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotCinitsemaine1).Value = nomNewTache
tacheInsert = True
Worksheets("Pièces semaine 1").Range("C" & lotCinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotCinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5
ElseIf groupNewTache = "C" Then
Worksheets("Pièces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotDinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotDinitsemaine1).Value = nomNewTache
tacheInsert = True
Worksheets("Pièces semaine 1").Range("C" & lotDinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotDinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5

ElseIf groupNewTache = "D" Then
Worksheets("Pièces semaine 1").Rows(lotEinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotEinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotEinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotEinitsemaine1).Value = nomNewTache
tacheInsert = True
Worksheets("Pièces semaine 1").Range("C" & lotEinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotEinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5
ElseIf groupNewTache = "E" Then
Worksheets("Pièces semaine 1").Rows(lotFinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotFinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotFinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotFinitsemaine1).Value = nomNewTache
tacheInsert = True
Worksheets("Pièces semaine 1").Range("C" & lotFinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotFinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5

ElseIf groupNewTache = "F" Then
Worksheets("Pièces semaine 1").Rows(lotGinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotGinitsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(lotGinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & lotGinitsemaine1).Value = nomNewTache
tacheInsert = True
Worksheets("Pièces semaine 1").Range("C" & lotGinitsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(lotGinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5

ElseIf groupNewTache = "G" Then
Lastrowsemaine1 = Worksheets("Pièces semaine 1").Cells(Worksheets("Pièces semaine 1").Rows.Count, "B").End(xlUp).Row
Worksheets("Pièces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & Lastrowsemaine1).Value = addOutil
Worksheets("Pièces semaine 1").Rows(Lastrowsemaine1).Insert
Worksheets("Pièces semaine 1").Range("B" & Lastrowsemaine1).Value = nomNewTache
tacheInsert = True
Worksheets("Pièces semaine 1").Range("C" & Lastrowsemaine1).Value = nbOutils
Worksheets("Pièces semaine 1").Cells(Lastrowsemaine1, 4 + jAproOutil).Interior.ColorIndex = 5

Else
MsgBox ("mauvais nom de lot de travail")
End If

Worksheets("Pièces semaine 1").Rows(lotEinit - 1).Insert

ElseIf jAproOutil >= 6 And jAproOutil <= 10 Then

tacheInsert = True

ElseIf jAproOutil >= 11 And jAproOutil <= 15 Then

tacheInsert = True

ElseIf jAproOutil >= 16 And jAproOutil <= 20 Then

tacheInsert = True

Else
MsgBox ("mauvaise semaine")
End If

endInputOutils = InputBox("ajouter un autre outil ? (oui ou non)", "ajout de tache")
If endInputOutils = "non" Then
    endOutils = True
End If

j = j + 1

Wend

'ajout nom de tache
'planning B. OK
'semaine B
'detail outil OK
'addoutil
'semaine b
'detail e to infinite
'nbOutil
'semaine C
'jOutil
'planning B
'semaine B
'detail outil
'jAproOutil
'planning B
'semaine B
'detail outil

End Sub

@cyrilferte
Copy link
Author

Sub Macroincertion()
'
' Macro d'ajout de cell
'
Dim groupCheck As String 'lettre du lot de travaux
Dim i As Integer

For i = 1 To 100
If Worksheets("Planning container").Range("A" & i).Value = "B" Then

   lotBinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "C" Then
  
   lotCinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "D" Then
   
   lotDinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "E" Then
  
   lotEinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "F" Then
   
   lotFinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "G" Then
   
   lotGinit = i
End If

Next
logGend = Worksheets("Planning container").Cells(Worksheets("Planning container").Rows.Count, "A").End(xlUp).Row
MsgBox (logGend)
For i = 1 To 1000
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "B" Then

   lotBinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine1 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "B" Then

   lotBinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine2 = i
End If

Next

For i = 1 To 1000
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "B" Then

   lotBinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine3 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "B" Then

   lotBinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine4 = i
End If

Next

'end loop i

groupNewTache = InputBox("lot de travaux ? (A, B, C...)", "ajout de tache")
nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")
refTache = InputBox("reference tache", "ajout de tache")
If groupNewTache = "A" Then
Worksheets("Planning container").Rows(lotBinit - 1).Insert
Worksheets("Detail des taches").Rows(lotBinit - 1).Insert
rowWrite = lotBinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "B" Then
Worksheets("Planning container").Rows(lotCinit - 1).Insert
Worksheets("Detail des taches").Rows(lotCinit - 1).Insert
rowWrite = lotCinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "C" Then
Worksheets("Planning container").Rows(lotDinit - 1).Insert
Worksheets("Detail des taches").Rows(lotDinit - 1).Insert
rowWrite = lotDinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "D" Then
Worksheets("Planning container").Rows(lotEinit - 1).Insert
Worksheets("Detail des taches").Rows(lotEinit - 1).Insert
rowWrite = lotEinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "E" Then
Worksheets("Planning container").Rows(lotFinit - 1).Insert
Worksheets("Detail des taches").Rows(lotFinit - 1).Insert
rowWrite = lotFinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "F" Then
Worksheets("Planning container").Rows(lotGinit - 1).Insert
Worksheets("Detail des taches").Rows(lotGinit - 1).Insert
rowWrite = lotGinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "G" Then
Worksheets("Planning container").Range("B" & lotGend).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
Else
MsgBox ("mauvais nom de lot de travail")
End If

endOutils = False

tacheInsert = False
nbDiffOutils = 0
While endOutils = False

addOutil = InputBox("nom de l'outil", "ajout d'outils")
refOutil = InputBox("réference de l'outil", "ajout d'outils")
nbOutils = InputBox("quantité ?", "ajout d'outils")
jTache = InputBox("jour d'utilisation ?", "ajout d'outils")
jAproOutil = jTache - 1


Worksheets("Detail des taches").Cells(rowWrite + 1, 5 + nbDiffOutils).Value = addOutil
nbDiffOutils = nbDiffOutils + 1

Worksheets("Planning container").Cells(rowWrite + 1, jTache + 2).Value = "x"
Worksheets("Detail des taches").Cells(rowWrite + 1, 3).Value = "j" + jTache
Worksheets("Detail des taches").Cells(rowWrite + 1, 4).Value = "j" & jAproOutil

'gestion des semaine

If jAproOutil <= 5 Then

If groupNewTache = "A" Then
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(lotBinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Range(lotBinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotBinitsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotBinitsemaine1 + nbDiffOutils).Insert
Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1 + nbDiffOutils).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotBinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotBinitsemaine1 + nbDiffOutils).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotBinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(lotCinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Range(lotCinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotCinitsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotCinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotCinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotCinitsemaine1).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotCinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Range(lotDinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotDinitsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotDinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotDinitsemaine1).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotDinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then

If tacheInsert = False Then
    Worksheets("Pieces semaine 1").Rows(lotEinitsemaine1).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Value = nomNewTache
     Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Interior.ColorIndex = 15
     Worksheets("Pieces semaine 1").Range(lotEinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
     Worksheets("Pieces semaine 1").Range("A" & lotEinitsemaine1).Value = refTache
    tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotEinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotEinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotEinitsemaine1).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotEinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "E" Then
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(lotFinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Range(lotFinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotFinitsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotFinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotFinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotFinitsemaine1).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotFinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

If tacheInsert = False Then
    Worksheets("Pieces semaine 1").Rows(lotGinitsemaine1).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Value = nomNewTache
     Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Interior.ColorIndex = 15
     Worksheets("Pieces semaine 1").Range(lotGinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
     Worksheets("Pieces semaine 1").Range("A" & lotGinitsemaine1).Value = refTache
    tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotGinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotGinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotGinitsemaine1).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotGinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine1 = Worksheets("Pi�eces semaine 1").Cells(Worksheets("Pi�eces semaine 1").Rows.Count, "B").End(xlUp).Row
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(Lastrowsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Range(Lastrowsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & Lastrowsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(Lastrowsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & Lastrowsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & Lastrowsemaine1).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(Lastrowsemaine1, 4 + jAproOutil).Interior.ColorIndex = 45

Else
MsgBox ("mauvais nom de lot de travail")
End If

ElseIf jAproOutil >= 6 And jAproOutil <= 10 Then

tacheInsert = True

ElseIf jAproOutil >= 11 And jAproOutil <= 15 Then

tacheInsert = True

ElseIf jAproOutil >= 16 And jAproOutil <= 20 Then

tacheInsert = True

Else
MsgBox ("mauvaise semaine")
End If

endInputOutils = InputBox("ajouter un autre outil ? (oui ou non)", "ajout de tache")
If endInputOutils = "non" Then
    endOutils = True
End If

j = j + 1

Wend

'ajout nom de tache
'planning B. OK
'semaine B
'detail outil OK
'addoutil
'semaine b
'detail e to infinite
'nbOutil
'semaine C
'jOutil
'planning B
'semaine B
'detail outil
'jAproOutil
'planning B
'semaine B
'detail outil

End Sub

@cyrilferte
Copy link
Author

Sub Macroincertion()
'
' Macro d'ajout de cell
'
Dim groupCheck As String 'lettre du lot de travaux
Dim i As Integer

For i = 1 To 100
If Worksheets("Planning container").Range("A" & i).Value = "B" Then

   lotBinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "C" Then
  
   lotCinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "D" Then
   
   lotDinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "E" Then
  
   lotEinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "F" Then
   
   lotFinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "G" Then
   
   lotGinit = i
End If

Next
logGend = Worksheets("Planning container").Cells(Worksheets("Planning container").Rows.Count, "A").End(xlUp).Row
MsgBox (logGend)
For i = 1 To 1000
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "B" Then

   lotBinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine1 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "B" Then

   lotBinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine2 = i
End If

Next

For i = 1 To 1000
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "B" Then

   lotBinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine3 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "B" Then

   lotBinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine4 = i
End If

Next

'end loop i

groupNewTache = InputBox("lot de travaux ? (A, B, C...)", "ajout de tache")
nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")
refTache = InputBox("reference tache", "ajout de tache")
If groupNewTache = "A" Then
Worksheets("Planning container").Rows(lotBinit - 1).Insert
Worksheets("Detail des taches").Rows(lotBinit - 1).Insert
rowWrite = lotBinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "B" Then
Worksheets("Planning container").Rows(lotCinit - 1).Insert
Worksheets("Detail des taches").Rows(lotCinit - 1).Insert
rowWrite = lotCinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "C" Then
Worksheets("Planning container").Rows(lotDinit - 1).Insert
Worksheets("Detail des taches").Rows(lotDinit - 1).Insert
rowWrite = lotDinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "D" Then
Worksheets("Planning container").Rows(lotEinit - 1).Insert
Worksheets("Detail des taches").Rows(lotEinit - 1).Insert
rowWrite = lotEinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "E" Then
Worksheets("Planning container").Rows(lotFinit - 1).Insert
Worksheets("Detail des taches").Rows(lotFinit - 1).Insert
rowWrite = lotFinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "F" Then
Worksheets("Planning container").Rows(lotGinit - 1).Insert
Worksheets("Detail des taches").Rows(lotGinit - 1).Insert
rowWrite = lotGinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "G" Then
Worksheets("Planning container").Range("B" & lotGend).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
Else
MsgBox ("mauvais nom de lot de travail")
End If

endOutils = False

tacheInsert = False
nbDiffOutils = 0
While endOutils = False

addOutil = InputBox("nom de l'outil", "ajout d'outils")
refOutil = InputBox("réference de l'outil", "ajout d'outils")
nbOutils = InputBox("quantité ?", "ajout d'outils")
jTache = InputBox("jour d'utilisation ?", "ajout d'outils")
jAproOutil = jTache - 1


Worksheets("Detail des taches").Cells(rowWrite + 1, 5 + nbDiffOutils).Value = addOutil
nbDiffOutils = nbDiffOutils + 1

Worksheets("Planning container").Cells(rowWrite + 1, jTache + 2).Value = "x"
Worksheets("Detail des taches").Cells(rowWrite + 1, 3).Value = "j" + jTache
Worksheets("Detail des taches").Cells(rowWrite + 1, 4).Value = "j" & jAproOutil

'gestion des semaine

If jAproOutil <= 5 Then

If groupNewTache = "A" Then
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(lotBinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Cells(lotBinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotBinitsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotBinitsemaine1 + nbDiffOutils).Insert
Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1 + nbDiffOutils).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotBinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotBinitsemaine1 + nbDiffOutils).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotBinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(lotCinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Cells(lotCinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotCinitsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotCinitsemaine1 + nbDiffOutils).Insert
Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1 + nbDiffOutils).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotCinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotCinitsemaine1 + nbDiffOutils).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotCinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(lotDinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Cells(lotDinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotDinitsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotDinitsemaine1 + nbDiffOutils).Insert
Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1 + nbDiffOutils).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotDinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotDinitsemaine1 + nbDiffOutils).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotDinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then

If tacheInsert = False Then
    Worksheets("Pieces semaine 1").Rows(lotEinitsemaine1).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Value = nomNewTache
     Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Interior.ColorIndex = 15
     Worksheets("Pieces semaine 1").Cells(lotEinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
     Worksheets("Pieces semaine 1").Range("A" & lotEinitsemaine1).Value = refTache
    tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotEinitsemaine1 + nbDiffOutils).Insert
Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1 + nbDiffOutils).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotEinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotEinitsemaine1 + nbDiffOutils).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotEinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "E" Then
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(lotFinitsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Cells(lotFinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotFinitsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotFinitsemaine1 + nbDiffOutils).Insert
Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1 + nbDiffOutils).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotFinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotFinitsemaine1 + nbDiffOutils).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotFinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

If tacheInsert = False Then
    Worksheets("Pieces semaine 1").Rows(lotGinitsemaine1).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Value = nomNewTache
     Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Interior.ColorIndex = 15
     Worksheets("Pieces semaine 1").Cells(lotGinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
     Worksheets("Pieces semaine 1").Range("A" & lotGinitsemaine1).Value = refTache
    tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(lotGinitsemaine1 + nbDiffOutils).Insert
Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1 + nbDiffOutils).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & lotGinitsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & lotGinitsemaine1 + nbDiffOutils).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(lotGinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine1 = Worksheets("Pi�eces semaine 1").Cells(Worksheets("Pi�eces semaine 1").Rows.Count, "B").End(xlUp).Row
If tacheInsert = False Then
Worksheets("Pieces semaine 1").Rows(Lastrowsemaine1).Insert
Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Value = nomNewTache
Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Interior.ColorIndex = 15
Worksheets("Pieces semaine 1").Cells(Lastrowsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & Lastrowsemaine1).Value = refTache
tacheInsert = True
End If
Worksheets("Pieces semaine 1").Rows(Lastrowsemaine1 + nbDiffOutils).Insert
Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1 + nbDiffOutils).Value = addOutil
Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
Worksheets("Pieces semaine 1").Range("A" & Lastrowsemaine1 + nbDiffOutils).Value = refOutil
Worksheets("Pieces semaine 1").Range("C" & Lastrowsemaine1 + nbDiffOutils).Value = nbOutils
Worksheets("Pieces semaine 1").Cells(Lastrowsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

Else
MsgBox ("mauvais nom de lot de travail")
End If

ElseIf jAproOutil >= 6 And jAproOutil <= 10 Then

tacheInsert = True

ElseIf jAproOutil >= 11 And jAproOutil <= 15 Then

tacheInsert = True

ElseIf jAproOutil >= 16 And jAproOutil <= 20 Then

tacheInsert = True

Else
MsgBox ("mauvaise semaine")
End If

endInputOutils = InputBox("ajouter un autre outil ? (oui ou non)", "ajout de tache")
If endInputOutils = "non" Then
    endOutils = True
End If
 Worksheets("Gestion des stocks-commandes").Range("A" & nbDiffOutils + 2).Value = addOutil
 Worksheets("Gestion des stocks-commandes").Range("B" & nbDiffOutils + 2).Value = refOutil
 
j = j + 1

Wend

'ajout nom de tache
'planning B. OK
'semaine B
'detail outil OK
'addoutil
'semaine b
'detail e to infinite
'nbOutil
'semaine C
'jOutil
'planning B
'semaine B
'detail outil
'jAproOutil
'planning B
'semaine B
'detail outil

End Sub

@cyrilferte
Copy link
Author

Sub Macroincertion()
'
' Macro d'ajout de cell
'
Dim groupCheck As String 'lettre du lot de travaux
Dim i As Integer

For i = 1 To 100
If Worksheets("Planning container").Range("A" & i).Value = "B" Then

   lotBinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "C" Then
  
   lotCinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "D" Then
   
   lotDinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "E" Then
  
   lotEinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "F" Then
   
   lotFinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "G" Then
   
   lotGinit = i
End If

Next
logGend = Worksheets("Planning container").Cells(Worksheets("Planning container").Rows.Count, "A").End(xlUp).Row
MsgBox (logGend)
For i = 1 To 1000
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "B" Then

   lotBinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine1 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "B" Then

   lotBinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine2 = i
End If

Next

For i = 1 To 1000
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "B" Then

   lotBinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine3 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "B" Then

   lotBinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine4 = i
End If

Next

'end loop i

groupNewTache = InputBox("lot de travaux ? (A, B, C...)", "ajout de tache")
nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")
refTache = InputBox("reference tache", "ajout de tache")
If groupNewTache = "A" Then
Worksheets("Planning container").Rows(lotBinit - 1).Insert
Worksheets("Detail des taches").Rows(lotBinit - 1).Insert
rowWrite = lotBinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "B" Then
Worksheets("Planning container").Rows(lotCinit - 1).Insert
Worksheets("Detail des taches").Rows(lotCinit - 1).Insert
rowWrite = lotCinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "C" Then
Worksheets("Planning container").Rows(lotDinit - 1).Insert
Worksheets("Detail des taches").Rows(lotDinit - 1).Insert
rowWrite = lotDinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "D" Then
Worksheets("Planning container").Rows(lotEinit - 1).Insert
Worksheets("Detail des taches").Rows(lotEinit - 1).Insert
rowWrite = lotEinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "E" Then
Worksheets("Planning container").Rows(lotFinit - 1).Insert
Worksheets("Detail des taches").Rows(lotFinit - 1).Insert
rowWrite = lotFinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "F" Then
Worksheets("Planning container").Rows(lotGinit - 1).Insert
Worksheets("Detail des taches").Rows(lotGinit - 1).Insert
rowWrite = lotGinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "G" Then
Worksheets("Planning container").Range("B" & lotGend).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
Else
MsgBox ("mauvais nom de lot de travail")
End If

endOutils = False

tacheInsert = False
nbDiffOutils = 0
While endOutils = False

addOutil = InputBox("nom de l'outil", "ajout d'outils")
refOutil = InputBox("réference de l'outil", "ajout d'outils")
nbOutils = InputBox("quantité ?", "ajout d'outils")
jTache = InputBox("jour d'utilisation ?", "ajout d'outils")
jAproOutil = jTache - 1


Worksheets("Detail des taches").Cells(rowWrite + 1, 5 + nbDiffOutils).Value = addOutil
nbDiffOutils = nbDiffOutils + 1

Worksheets("Planning container").Cells(rowWrite + 1, jTache + 2).Value = "x"
Worksheets("Detail des taches").Cells(rowWrite + 1, 3).Value = "j" + jTache
Worksheets("Detail des taches").Cells(rowWrite + 1, 4).Value = "j" & jAproOutil

'gestion des semaine

If jAproOutil <= 5 Then

If groupNewTache = "A" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotBinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1).Value = nomNewTache
        Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 1").Cells(lotBinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 1").Range("A" & lotBinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotBinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotBinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotBinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotBinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotCinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotCinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotCinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotCinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotCinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotCinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotCinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotDinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotDinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotDinitsemaine1).Value = refTache
        tacheInsert = True
    End If
      Worksheets("Pieces semaine 1").Rows(lotDinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotDinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotDinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotDinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then
    
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotEinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotEinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotEinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotEinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotEinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotEinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotEinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "E" Then
    If tacheInsert = False Then
         Worksheets("Pieces semaine 1").Rows(lotFinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotFinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotFinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotFinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotFinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotFinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotFinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotGinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotGinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotGinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotGinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotGinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotGinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotGinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine1 = Worksheets("Pieces semaine 1").Cells(Worksheets("Pieces semaine 1").Rows.Count, "B").End(xlUp).Row
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(Lastrowsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Value = nomNewTache
        Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 1").Cells(Lastrowsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 1").Range("A" & Lastrowsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(Lastrowsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & Lastrowsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & Lastrowsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(Lastrowsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

Else
    MsgBox ("mauvais nom de lot de travail")
End If

ElseIf jAproOutil >= 6 And jAproOutil <= 10 Then

If groupNewTache = "A" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotBinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotBinitsemaine2).Value = nomNewTache
        Worksheets("Pieces semaine 2").Range("B" & lotBinitsemaine2).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 2").Cells(lotBinitsemaine2, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 2").Range("A" & lotBinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotBinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotBinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotBinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotBinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotBinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotBinitsemaine2 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotCinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotCinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotCinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotCinitsemaine2, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotCinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotCinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotCinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotCinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotCinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotCinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotCinitsemaine2 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotDinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotDinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotDinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotDinitsemaine2, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotDinitsemaine2).Value = refTache
        tacheInsert = True
    End If
      Worksheets("Pieces semaine 2").Rows(lotDinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotDinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotDinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotDinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotDinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotDinitsemaine2 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then
    
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotEinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotEinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotEinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotEinitsemaine2, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotEinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotEinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotEinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotEinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotEinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotEinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotEinitsemaine2 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "E" Then
    If tacheInsert = False Then
         Worksheets("Pieces semaine 2").Rows(lotFinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotFinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotFinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotFinitsemaine2, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotFinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotFinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotFinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotFinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotFinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotFinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotFinitsemaine2 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotGinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotGinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotGinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotGinitsemaine2, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotGinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotGinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotGinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotGinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotGinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotGinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotGinitsemaine2 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine2 = Worksheets("Pieces semaine 2").Cells(Worksheets("Pieces semaine 2").Rows.Count, "B").End(xlUp).Row
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(Lastrowsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & Lastrowsemaine2).Value = nomNewTache
        Worksheets("Pieces semaine 2").Range("B" & Lastrowsemaine2).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 2").Cells(Lastrowsemaine2, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 2").Range("A" & Lastrowsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(Lastrowsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & Lastrowsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & Lastrowsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & Lastrowsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & Lastrowsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(Lastrowsemaine2 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

Else
    MsgBox ("mauvais nom de lot de travail")
End If

ElseIf jAproOutil >= 11 And jAproOutil <= 15 Then

If groupNewTache = "A" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotBinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotBinitsemaine3).Value = nomNewTache
        Worksheets("Pieces semaine 3").Range("B" & lotBinitsemaine3).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 3").Cells(lotBinitsemaine3, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 3").Range("A" & lotBinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotBinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotBinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotBinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotBinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotBinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotBinitsemaine3 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotCinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotCinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotCinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotCinitsemaine3, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotCinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotCinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotCinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotCinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotCinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotCinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotCinitsemaine3 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotDinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotDinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotDinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotDinitsemaine3, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotDinitsemaine3).Value = refTache
        tacheInsert = True
    End If
      Worksheets("Pieces semaine 3").Rows(lotDinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotDinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotDinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotDinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotDinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotDinitsemaine3 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then
    
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotEinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotEinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotEinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotEinitsemaine3, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotEinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotEinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotEinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotEinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotEinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotEinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotEinitsemaine3 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "E" Then
    If tacheInsert = False Then
         Worksheets("Pieces semaine 3").Rows(lotFinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotFinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotFinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotFinitsemaine3, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotFinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotFinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotFinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotFinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotFinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotFinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotFinitsemaine3 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotGinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotGinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotGinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotGinitsemaine3, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotGinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotGinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotGinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotGinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotGinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotGinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotGinitsemaine3 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine3 = Worksheets("Pieces semaine 3").Cells(Worksheets("Pieces semaine 3").Rows.Count, "B").End(xlUp).Row
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(Lastrowsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & Lastrowsemaine3).Value = nomNewTache
        Worksheets("Pieces semaine 3").Range("B" & Lastrowsemaine3).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 3").Cells(Lastrowsemaine3, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 3").Range("A" & Lastrowsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(Lastrowsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & Lastrowsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & Lastrowsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & Lastrowsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & Lastrowsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(Lastrowsemaine3 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

Else
    MsgBox ("mauvais nom de lot de travail")
End If

ElseIf jAproOutil >= 16 And jAproOutil <= 20 Then

If groupNewTache = "A" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotBinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotBinitsemaine4).Value = nomNewTache
        Worksheets("Pieces semaine 4").Range("B" & lotBinitsemaine4).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 4").Cells(lotBinitsemaine4, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 4").Range("A" & lotBinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotBinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotBinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotBinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotBinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotBinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotBinitsemaine4 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotCinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotCinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotCinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotCinitsemaine4, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotCinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotCinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotCinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotCinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotCinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotCinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotCinitsemaine4 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotDinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotDinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotDinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotDinitsemaine4, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotDinitsemaine4).Value = refTache
        tacheInsert = True
    End If
      Worksheets("Pieces semaine 4").Rows(lotDinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotDinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotDinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotDinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotDinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotDinitsemaine4 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then
    
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotEinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotEinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotEinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotEinitsemaine4, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotEinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotEinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotEinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotEinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotEinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotEinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotEinitsemaine4 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "E" Then
    If tacheInsert = False Then
         Worksheets("Pieces semaine 4").Rows(lotFinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotFinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotFinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotFinitsemaine4, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotFinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotFinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotFinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotFinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotFinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotFinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotFinitsemaine2 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotGinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotGinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotGinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotGinitsemaine4, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotGinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotGinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotGinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotGinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotGinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotGinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotGinitsemaine4 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine4 = Worksheets("Pieces semaine 4").Cells(Worksheets("Pieces semaine 4").Rows.Count, "B").End(xlUp).Row
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(Lastrowsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & Lastrowsemaine4).Value = nomNewTache
        Worksheets("Pieces semaine 4").Range("B" & Lastrowsemaine4).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 4").Cells(Lastrowsemaine4, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 4").Range("A" & Lastrowsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(Lastrowsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & Lastrowsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & Lastrowsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & Lastrowsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & Lastrowsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(Lastrowsemaine4 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

Else
    MsgBox ("mauvais nom de lot de travail")
End If

Else
MsgBox ("mauvaise semaine")
End If

endInputOutils = InputBox("ajouter un autre outil ? (oui ou non)", "ajout de tache")
If endInputOutils = "non" Then
    endOutils = True
End If
 Worksheets("Gestion des stocks-commandes").Range("A" & nbDiffOutils + 2).Value = addOutil
 Worksheets("Gestion des stocks-commandes").Range("B" & nbDiffOutils + 2).Value = refOutil
 
j = j + 1

Wend

'ajout nom de tache
'planning B. OK
'semaine B
'detail outil OK
'addoutil
'semaine b
'detail e to infinite
'nbOutil
'semaine C
'jOutil
'planning B
'semaine B
'detail outil
'jAproOutil
'planning B
'semaine B
'detail outil

End Sub

@cyrilferte
Copy link
Author

Sub Macroincertion()
'
' Macro d'ajout de cell
'
Dim groupCheck As String 'lettre du lot de travaux
Dim i As Integer

For i = 1 To 100
If Worksheets("Planning container").Range("A" & i).Value = "B" Then

   lotBinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "C" Then
  
   lotCinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "D" Then
   
   lotDinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "E" Then
  
   lotEinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "F" Then
   
   lotFinit = i
End If
If Worksheets("Planning container").Range("A" & i).Value = "G" Then
   
   lotGinit = i
End If

Next
logGend = Worksheets("Planning container").Cells(Worksheets("Planning container").Rows.Count, "A").End(xlUp).Row
MsgBox (logGend)
For i = 1 To 1000
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "B" Then

   lotBinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine1 = i
End If
If Worksheets("Pieces semaine 1").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine1 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "B" Then

   lotBinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine2 = i
End If
If Worksheets("Pieces semaine 2").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine2 = i
End If

Next

For i = 1 To 1000
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "B" Then

   lotBinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine3 = i
End If
If Worksheets("Pieces semaine 3").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine3 = i
End If

Next
For i = 1 To 1000
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "B" Then

   lotBinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "C" Then
  
   lotCinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "D" Then
   
   lotDinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "E" Then
  
   lotEinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "F" Then
   
   lotFinitsemaine4 = i
End If
If Worksheets("Pieces semaine 4").Range("A" & i).Value = "G" Then
   
   lotGinitsemaine4 = i
End If

Next

'end loop i

groupNewTache = InputBox("lot de travaux ? (A, B, C...)", "ajout de tache")
nomNewTache = InputBox("nom de la nouvelle tache", "ajout de tache")
refTache = InputBox("reference tache", "ajout de tache")
If groupNewTache = "A" Then
Worksheets("Planning container").Rows(lotBinit - 1).Insert
Worksheets("Detail des taches").Rows(lotBinit - 1).Insert
rowWrite = lotBinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "B" Then
Worksheets("Planning container").Rows(lotCinit - 1).Insert
Worksheets("Detail des taches").Rows(lotCinit - 1).Insert
rowWrite = lotCinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "C" Then
Worksheets("Planning container").Rows(lotDinit - 1).Insert
Worksheets("Detail des taches").Rows(lotDinit - 1).Insert
rowWrite = lotDinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "D" Then
Worksheets("Planning container").Rows(lotEinit - 1).Insert
Worksheets("Detail des taches").Rows(lotEinit - 1).Insert
rowWrite = lotEinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "E" Then
Worksheets("Planning container").Rows(lotFinit - 1).Insert
Worksheets("Detail des taches").Rows(lotFinit - 1).Insert
rowWrite = lotFinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "F" Then
Worksheets("Planning container").Rows(lotGinit - 1).Insert
Worksheets("Detail des taches").Rows(lotGinit - 1).Insert
rowWrite = lotGinit - 2
Worksheets("Planning container").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
ElseIf groupNewTache = "G" Then
Worksheets("Planning container").Range("B" & lotGend).Value = nomNewTache
Worksheets("Detail des taches").Range("B" & rowWrite + 1).Value = nomNewTache
Worksheets("Planning container").Range("A" & rowWrite + 1).Value = refTache
Worksheets("Detail des taches").Range("A" & rowWrite + 1).Value = refTache
Else
MsgBox ("mauvais nom de lot de travail")
End If

endOutils = False

tacheInsert = False
nbDiffOutils = 0
While endOutils = False

addOutil = InputBox("nom de l'outil", "ajout d'outils")
refOutil = InputBox("réference de l'outil", "ajout d'outils")
nbOutils = InputBox("quantité ?", "ajout d'outils")
jTache = InputBox("jour d'utilisation ?", "ajout d'outils")
jAproOutil = jTache - 1


Worksheets("Detail des taches").Cells(rowWrite + 1, 5 + nbDiffOutils).Value = addOutil
nbDiffOutils = nbDiffOutils + 1

Worksheets("Planning container").Cells(rowWrite + 1, jTache + 2).Value = "x"
Worksheets("Detail des taches").Cells(rowWrite + 1, 3).Value = "j" + jTache
Worksheets("Detail des taches").Cells(rowWrite + 1, 4).Value = "j" & jAproOutil

'gestion des semaine

If jAproOutil <= 5 Then

If groupNewTache = "A" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotBinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1).Value = nomNewTache
        Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 1").Cells(lotBinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 1").Range("A" & lotBinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotBinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotBinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotBinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotBinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotBinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotCinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotCinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotCinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotCinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotCinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotCinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotCinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotCinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotDinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotDinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotDinitsemaine1).Value = refTache
        tacheInsert = True
    End If
      Worksheets("Pieces semaine 1").Rows(lotDinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotDinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotDinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotDinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotDinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then
    
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotEinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotEinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotEinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotEinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotEinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotEinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotEinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotEinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45
ElseIf groupNewTache = "E" Then
    If tacheInsert = False Then
         Worksheets("Pieces semaine 1").Rows(lotFinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotFinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotFinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotFinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotFinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotFinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotFinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotFinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(lotGinitsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Value = nomNewTache
         Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 1").Cells(lotGinitsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 1").Range("A" & lotGinitsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(lotGinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & lotGinitsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & lotGinitsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & lotGinitsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(lotGinitsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine1 = Worksheets("Pieces semaine 1").Cells(Worksheets("Pieces semaine 1").Rows.Count, "B").End(xlUp).Row
    If tacheInsert = False Then
        Worksheets("Pieces semaine 1").Rows(Lastrowsemaine1).Insert
        Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Value = nomNewTache
        Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 1").Cells(Lastrowsemaine1, 4 + jAproOutil).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 1").Range("A" & Lastrowsemaine1).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 1").Rows(Lastrowsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 1").Range("B" & Lastrowsemaine1 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 1").Range("A" & Lastrowsemaine1 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 1").Range("C" & Lastrowsemaine1 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 1").Cells(Lastrowsemaine1 + nbDiffOutils, 4 + jAproOutil).Interior.ColorIndex = 45

Else
    MsgBox ("mauvais nom de lot de travail")
End If

ElseIf jAproOutil >= 6 And jAproOutil <= 10 Then

If groupNewTache = "A" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotBinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotBinitsemaine2).Value = nomNewTache
        Worksheets("Pieces semaine 2").Range("B" & lotBinitsemaine2).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 2").Cells(lotBinitsemaine2, 4 + jAproOutil - 6).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 2").Range("A" & lotBinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotBinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotBinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotBinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotBinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotBinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotBinitsemaine2 + nbDiffOutils, 4 + jAproOutil - 6).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotCinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotCinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotCinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotCinitsemaine2, 4 + jAproOutil - 6).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotCinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotCinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotCinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotCinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotCinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotCinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotCinitsemaine2 + nbDiffOutils, 4 + jAproOutil - 6).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotDinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotDinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotDinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotDinitsemaine2, 4 + jAproOutil - 6).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotDinitsemaine2).Value = refTache
        tacheInsert = True
    End If
      Worksheets("Pieces semaine 2").Rows(lotDinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotDinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotDinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotDinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotDinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotDinitsemaine2 + nbDiffOutils, 4 + jAproOutil - 6).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then
    
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotEinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotEinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotEinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotEinitsemaine2, 4 + jAproOutil - 6).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotEinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotEinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotEinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotEinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotEinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotEinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotEinitsemaine2 + nbDiffOutils, 4 + jAproOutil - 6).Interior.ColorIndex = 45
ElseIf groupNewTache = "E" Then
    If tacheInsert = False Then
         Worksheets("Pieces semaine 2").Rows(lotFinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotFinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotFinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotFinitsemaine2, 4 + jAproOutil - 6).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotFinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotFinitsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotFinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotFinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotFinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotFinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotFinitsemaine2 + nbDiffOutils, 4 + jAproOutil - 6).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(lotGinitsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & lotGinitsemaine2).Value = nomNewTache
         Worksheets("Pieces semaine 2").Range("B" & lotGinitsemaine2).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 2").Cells(lotGinitsemaine2, 4 + jAproOutil - 6).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 2").Range("A" & lotGinitsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(lotGinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & lotGinitsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & lotGinitsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & lotGinitsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & lotGinitsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(lotGinitsemaine2 + nbDiffOutils, 4 + jAproOutil - 6).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine2 = Worksheets("Pieces semaine 2").Cells(Worksheets("Pieces semaine 2").Rows.Count, "B").End(xlUp).Row
    If tacheInsert = False Then
        Worksheets("Pieces semaine 2").Rows(Lastrowsemaine2).Insert
        Worksheets("Pieces semaine 2").Range("B" & Lastrowsemaine2).Value = nomNewTache
        Worksheets("Pieces semaine 2").Range("B" & Lastrowsemaine2).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 2").Cells(Lastrowsemaine2, 4 + jAproOutil - 6).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 2").Range("A" & Lastrowsemaine2).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 2").Rows(Lastrowsemaine2 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 2").Range("B" & Lastrowsemaine2 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 2").Range("B" & Lastrowsemaine2 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 2").Range("A" & Lastrowsemaine2 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 2").Range("C" & Lastrowsemaine2 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 2").Cells(Lastrowsemaine2 + nbDiffOutils, 4 + jAproOutil - 6).Interior.ColorIndex = 45

Else
    MsgBox ("mauvais nom de lot de travail")
End If

ElseIf jAproOutil >= 11 And jAproOutil <= 15 Then

If groupNewTache = "A" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotBinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotBinitsemaine3).Value = nomNewTache
        Worksheets("Pieces semaine 3").Range("B" & lotBinitsemaine3).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 3").Cells(lotBinitsemaine3, 4 + jAproOutil - 11).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 3").Range("A" & lotBinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotBinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotBinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotBinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotBinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotBinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotBinitsemaine3 + nbDiffOutils, 4 + jAproOutil - 11).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotCinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotCinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotCinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotCinitsemaine3, 4 + jAproOutil - 11).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotCinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotCinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotCinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotCinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotCinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotCinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotCinitsemaine3 + nbDiffOutils, 4 + jAproOutil - 11).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotDinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotDinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotDinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotDinitsemaine3, 4 + jAproOutil - 11).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotDinitsemaine3).Value = refTache
        tacheInsert = True
    End If
      Worksheets("Pieces semaine 3").Rows(lotDinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotDinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotDinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotDinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotDinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotDinitsemaine3 + nbDiffOutils, 4 + jAproOutil - 11).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then
    
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotEinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotEinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotEinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotEinitsemaine3, 4 + jAproOutil - 11).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotEinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotEinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotEinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotEinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotEinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotEinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotEinitsemaine3 + nbDiffOutils, 4 + jAproOutil - 11).Interior.ColorIndex = 45
ElseIf groupNewTache = "E" Then
    If tacheInsert = False Then
         Worksheets("Pieces semaine 3").Rows(lotFinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotFinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotFinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotFinitsemaine3, 4 + jAproOutil - 11).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotFinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotFinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotFinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotFinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotFinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotFinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotFinitsemaine3 + nbDiffOutils, 4 + jAproOutil - 11).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(lotGinitsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & lotGinitsemaine3).Value = nomNewTache
         Worksheets("Pieces semaine 3").Range("B" & lotGinitsemaine3).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 3").Cells(lotGinitsemaine3, 4 + jAproOutil - 11).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 3").Range("A" & lotGinitsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(lotGinitsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & lotGinitsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & lotGinitsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & lotGinitsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & lotGinitsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(lotGinitsemaine3 + nbDiffOutils, 4 + jAproOutil - 11).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine3 = Worksheets("Pieces semaine 3").Cells(Worksheets("Pieces semaine 3").Rows.Count, "B").End(xlUp).Row
    If tacheInsert = False Then
        Worksheets("Pieces semaine 3").Rows(Lastrowsemaine3).Insert
        Worksheets("Pieces semaine 3").Range("B" & Lastrowsemaine3).Value = nomNewTache
        Worksheets("Pieces semaine 3").Range("B" & Lastrowsemaine3).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 3").Cells(Lastrowsemaine3, 4 + jAproOutil - 11).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 3").Range("A" & Lastrowsemaine3).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 3").Rows(Lastrowsemaine3 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 3").Range("B" & Lastrowsemaine3 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 3").Range("B" & Lastrowsemaine3 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 3").Range("A" & Lastrowsemaine3 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 3").Range("C" & Lastrowsemaine3 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 3").Cells(Lastrowsemaine3 + nbDiffOutils, 4 + jAproOutil - 11).Interior.ColorIndex = 45

Else
    MsgBox ("mauvais nom de lot de travail")
End If

ElseIf jAproOutil >= 16 And jAproOutil <= 20 Then

If groupNewTache = "A" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotBinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotBinitsemaine4).Value = nomNewTache
        Worksheets("Pieces semaine 4").Range("B" & lotBinitsemaine4).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 4").Cells(lotBinitsemaine4, 4 + jAproOutil - 16).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 4").Range("A" & lotBinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotBinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotBinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotBinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotBinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotBinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotBinitsemaine4 + nbDiffOutils, 4 + jAproOutil - 16).Interior.ColorIndex = 45
ElseIf groupNewTache = "B" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotCinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotCinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotCinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotCinitsemaine4, 4 + jAproOutil - 16).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotCinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotCinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotCinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotCinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotCinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotCinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotCinitsemaine4 + nbDiffOutils, 4 + jAproOutil - 16).Interior.ColorIndex = 45
ElseIf groupNewTache = "C" Then
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotDinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotDinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotDinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotDinitsemaine4, 4 + jAproOutil - 16).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotDinitsemaine4).Value = refTache
        tacheInsert = True
    End If
      Worksheets("Pieces semaine 4").Rows(lotDinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotDinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotDinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotDinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotDinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotDinitsemaine4 + nbDiffOutils, 4 + jAproOutil - 16).Interior.ColorIndex = 45

ElseIf groupNewTache = "D" Then
    
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotEinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotEinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotEinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotEinitsemaine4, 4 + jAproOutil - 16).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotEinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotEinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotEinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotEinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotEinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotEinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotEinitsemaine4 + nbDiffOutils, 4 + jAproOutil - 16).Interior.ColorIndex = 45
ElseIf groupNewTache = "E" Then
    If tacheInsert = False Then
         Worksheets("Pieces semaine 4").Rows(lotFinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotFinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotFinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotFinitsemaine4, 4 + jAproOutil - 16).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotFinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotFinitsemaine1 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotFinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotFinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotFinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotFinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotFinitsemaine2 + nbDiffOutils, 4 + jAproOutil - 16).Interior.ColorIndex = 45

ElseIf groupNewTache = "F" Then

    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(lotGinitsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & lotGinitsemaine4).Value = nomNewTache
         Worksheets("Pieces semaine 4").Range("B" & lotGinitsemaine4).Interior.ColorIndex = 15
         Worksheets("Pieces semaine 4").Cells(lotGinitsemaine4, 4 + jAproOutil - 16).Interior.ColorIndex = 2
         Worksheets("Pieces semaine 4").Range("A" & lotGinitsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(lotGinitsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & lotGinitsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & lotGinitsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & lotGinitsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & lotGinitsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(lotGinitsemaine4 + nbDiffOutils, 4 + jAproOutil - 16).Interior.ColorIndex = 45

ElseIf groupNewTache = "G" Then
Lastrowsemaine4 = Worksheets("Pieces semaine 4").Cells(Worksheets("Pieces semaine 4").Rows.Count, "B").End(xlUp).Row
    If tacheInsert = False Then
        Worksheets("Pieces semaine 4").Rows(Lastrowsemaine4).Insert
        Worksheets("Pieces semaine 4").Range("B" & Lastrowsemaine4).Value = nomNewTache
        Worksheets("Pieces semaine 4").Range("B" & Lastrowsemaine4).Interior.ColorIndex = 15
        Worksheets("Pieces semaine 4").Cells(Lastrowsemaine4, 4 + jAproOutil - 16).Interior.ColorIndex = 2
        Worksheets("Pieces semaine 4").Range("A" & Lastrowsemaine4).Value = refTache
        tacheInsert = True
    End If
    Worksheets("Pieces semaine 4").Rows(Lastrowsemaine4 + nbDiffOutils).Insert
    Worksheets("Pieces semaine 4").Range("B" & Lastrowsemaine4 + nbDiffOutils).Value = addOutil
    Worksheets("Pieces semaine 4").Range("B" & Lastrowsemaine4 + nbDiffOutils).Interior.ColorIndex = 2
    Worksheets("Pieces semaine 4").Range("A" & Lastrowsemaine4 + nbDiffOutils).Value = refOutil
    Worksheets("Pieces semaine 4").Range("C" & Lastrowsemaine4 + nbDiffOutils).Value = nbOutils
    Worksheets("Pieces semaine 4").Cells(Lastrowsemaine4 + nbDiffOutils, 4 + jAproOutil - 16).Interior.ColorIndex = 45

Else
    MsgBox ("mauvais nom de lot de travail")
End If

Else
MsgBox ("mauvaise semaine")
End If

endInputOutils = InputBox("ajouter un autre outil ? (oui ou non)", "ajout de tache")
If endInputOutils = "non" Then
    endOutils = True
End If
 Worksheets("Gestion des stocks-commandes").Range("A" & nbDiffOutils + 2).Value = addOutil
 Worksheets("Gestion des stocks-commandes").Range("B" & nbDiffOutils + 2).Value = refOutil
 
j = j + 1

Wend

'ajout nom de tache
'planning B. OK
'semaine B
'detail outil OK
'addoutil
'semaine b
'detail e to infinite
'nbOutil
'semaine C
'jOutil
'planning B
'semaine B
'detail outil
'jAproOutil
'planning B
'semaine B
'detail outil

End Sub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment