Allez dans le module 2 :
1. remplacez la sub planning par celle ci-dessous:
Sub planning()
Dim i As Integer
Feuil1.Unprotect
If lig > 0 Then
With Range(Cells(lig, 24), Cells(lig, 500))
.UnMerge
.ClearContents
.Interior.Color = xlNone
End With
If WorksheetFunction.CountA(Range("Q" & lig & ":V" & lig)) = 6 Then
Call maj(lig)
For i = 1 To Range("T" & lig) / 0.5
ActiveSheet.Unprotect
Cells(lig, i + 23).Interior.Color = coul
Next i
Cells(lig, 24) = ref
Range(Cells(lig, 24), Cells(lig, i + 22)).HorizontalAlignment = xlLeft
End If
lig = 0
Else:
Dim j As Integer
For i = 5 To Cells(Rows.Count, 2).End(xlUp).Row
With Range(Cells(i, 24), Cells(i, 500))
.ClearContents
.Interior.Color = xlNone
End With
If WorksheetFunction.CountA(Range("Q" & i & ":V" & i)) = 6 Then
Call maj(i)
For j = 1 To Range("T" & i) / 0.5
Cells(i, j + 23).Interior.Color = coul
Next j
Cells(i, 24) = ref
Range(Cells(i, 24), Cells(i, j + 22)).HorizontalAlignment = xlLeft
End If
Next i
End If
ref = vbNullString
coul = vbNullString
'Feuil1.Protect
End Sub
2. remplacez la sub maj par ceci
Sub maj(i As Integer)
Dim refdem As String, refpart As String, refdate As String
Range("C" & i) = Replace(Range("C" & i), "-", "_") 'changer tiret par souligne
refdem = Right(Range("C" & i).Value, Len(Range("C" & i).Value) - InStrRev(Range("C" & i).Value, "_")) 'ref essai
refpart = Range("F" & i).Value 'ref piece
refdate = Format(Range("V" & i), "dd/mm") 'refdate
If UCase(Range("R" & i)) = "T" Or UCase(Range("R" & i)) = "A" Then
ref = refdem
coul = RGB(217, 217, 217)
Else:
ref = refdem & " - " & refpart & " - " & refdate
coul = Range("B" & i).Interior.Color
End If
End Sub
NB : ne supprimez pas les déclarations de variables (dim,.....) en entête du module bien entendu