Ok on passe au suivant
1. module 2 : Supprimez tous les codes et remplacez les par ceux-ci
Option Explicit
Public lig As Integer
Public couleur As Long
Dim ref As String
Dim coul
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
With Range(Cells(lig, 24), Cells(lig, i + 22))
.Merge
.HorizontalAlignment = xlCenter
End With
End If
Else:
Dim j As Integer
For i = 5 To Cells(Rows.Count, 2).End(xlUp).Row
With Range(Cells(i, 24), Cells(i, 500))
.UnMerge
.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
With Range(Cells(i, 24), Cells(i, j + 22))
.Merge
.HorizontalAlignment = xlCenter
End With
End If
Next i
End If
'lig = 0
ref = vbNullString
coul = vbNullString
Feuil1.Protect
End Sub
Sub maj(i As Integer)
Dim refdem As String, refpart As String, refdate As String
coul = Range("B" & i).Interior.Color
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
ref = refdem & " - " & refpart & " - " & refdate
End Sub
Là vous pouvez refaire un test en cliquant sur le bouton Mise à jour.
Une fois fait, il restera l'Userform à vous donner