Avant de commencer à régler ton problème commençons par essayer de simplifier ton code.
Voici un exemple de simplification a tester pour une meilleure lisibilité:
Code simplifié:
Private Sub Worksheet_Change(ByVal Target As Range) 'Quand la feuille (Worksheet) change, ce programme se lance
Dim Ws_demande As Worksheet
Dim i&, n&, y&
Dim x As Double
Set Ws_demande = Sheets("Demande")
y = 5
Call Cloche
If Target.Count > 1 Then Exit Sub
If Target = "Terminé" Then Target.Interior.Color = RGB(50, 200, 100) 'Si RAS la cellule devient verte
'ActiveCell.Font.ColorIndex = 51
For Each Cell In Range("J7:P10")
If Cell.Value = "" Then Cell.Interior.Color = xlColorIndexNone 'Enleve la couleur des cellules vides
Next Cell
If Not Intersect(Target, Range("J7:P9")) Is Nothing Then
Call Heures(Target.Column) 'Si les cellules qui changent sont J7 ou J8
For i = 4 To 20
With Ws_demande
If .Range("F" & i).Value = 600 Then 'On cherche les pièces de la machine à mesurer
For col = 9 To 12
.Cells(4, col) = .Cells(i, col - 8) 'Transmet les données vers les pièces terminées
Next col
For col = 14 To 16
.Cells(4, col) = Format(Time, "h:mm;@") ' pour donner un format à la cellule avant d'y écrire
Next col
.Range("O4").Value = .Range("H" & i).Value
.Range("M4").Value = .Range("E" & i).Value
.Range("P4") = CDate(.Range("N4")) - CDate(.Range("G" & i)) 'Temps pris pour mesurer
x = .Range("H" & i) - CDate(.Range("P4")) 'Compare le temps mis au temps attendu
.Range("Q4").Value = IIf(x > 0, "Avance", "Retard")
x = IIf(x > 0, x, -x)
.Range("R4").Value = Format(Time, "h:mm;@") 'Donne un format à la cellule
.Range("R4").Value = x 'Prend la vameur de l'écart entre temps attendu et temps mis
For n = i + 1 To n = i + 10
If .Range("B" & n) = "" Then
.Rows(y).Insert
.Rows(y).Locked = False
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True
n = n + 1
.Range("L" & y) = .Range("D" & n).Value
.Range("M" & y) = .Range("E" & n).Value
n = n + 1
y = y + 1
End If
Next n
.Range(.Cells(i, 1), .Cells(i, 8)).ClearContents 'Vide les pièces à mesurer
.Rows(4).Insert
.Rows(4).Locked = False
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True
End If
End With
Next i
End If
End Sub