Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.CommandBars("Fill Color").Visible = True
Dim Z As Range, Y As Integer
On Error Resume Next
If Not Intersect(Target, Range("f11:Bw20")) Is Nothing And Target.Rows.Count = 1 Then 'adapter la plage
Set Z = Range("B8")
Y = Target.Count > 1
If Y Then
If ActiveCell <> 0 Then
Selection.UnMerge
Selection = 0
Selection.Font.ColorIndex = 2
Selection.Interior.ColorIndex = xlNone
Bordures
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=f$8=""s"""
Selection.FormatConditions(1).Interior.Pattern = xlGray16
Else
x1 = Selection.Cells(1, 1).Column - 5
x2 = x1 + Selection.Columns.Count
x1 = Format((x1 * 0.25 / 24) + 0.25, "h""h""mm")
x2 = Format((x2 * 0.25 / 24) + 0.25, "h""h""mm")
deb = Replace(x1, "h", ":") + ":00"
deb = CDate(deb)
fin = Replace(x2, "h", ":") + ":00"
fin = CDate(fin)
delta = fin - deb
delta = Format(delta, "h""h""mm")
Application.DisplayAlerts = False
Selection.Merge
Application.DisplayAlerts = True
Selection = Z.Value & " (" & x1 & " à " & x2 & " soit " & delta & ")"
Selection.Font.ColorIndex = 1
Selection.Interior.ColorIndex = Z.Interior.ColorIndex
Bordures
End If
End If
If Not Y Then
If Target <> 0 Then
Target = 0
Target.Font.ColorIndex = 2
Target.Interior.ColorIndex = xlNone
Else
' x1 = Target.Column - 5
' x2 = Format(((x1 + 1) * 0.25 / 24) + 0.25, "h""h""mm")
' x1 = Format((x1 * 0.25 / 24) + 0.25, "h""h""mm")
Target = Z.Value '& " (" & x1 & "-" & x2 & ")"
Target.Font.ColorIndex = 1
Target.Interior.ColorIndex = Z.Interior.ColorIndex
End If
End If
Z.Activate
End If