Private Sub CommandButton1_Click() 'Phase
If Cells(ActiveCell.Row, 2) Like "Sous-phase*" Then Exit Sub
Dim n&
n = Application.CountIf(Range("A1:A" & ActiveCell.Row), "Phase*") + 1
With Cells(ActiveCell.Row, 1)
With .Resize(, 6).Font
.Size = 11
.Bold = True 'gras
End With
.Value = "Phase " & n
End With
End Sub
Private Sub CommandButton2_Click() 'S.Phase
If ActiveCell.Row = 1 Then Exit Sub
If Cells(ActiveCell.Row, 1) Like "Phase*" Or Cells(ActiveCell.Row - 1, 2) Like "Sous-phase*" Then Exit Sub
Dim lig1&, lig, n&, x$
lig1 = Cells(ActiveCell.Row, 1).End(xlUp).Row
lig = Cells(ActiveCell.Row, 2).End(xlUp).Row
If lig < lig1 Then lig = lig1
n = Val(Replace(Cells(lig, 2), "Sous-phase", "")) + 1
With Cells(ActiveCell.Row, 1)
.Resize(, 6).Font.Size = 10 'RAZ
.Resize(, 6).Font.Bold = False 'RAZ
.Resize(, 7).Interior.Color = RGB(217, 217, 217) 'gris
.Cells(1, 2) = "Sous-phase " & n
End With
For n = lig1 + 1 To ActiveCell.Row
If Cells(n, 2) Like "Sous-phase*" Then x = x & "," & "F" & n
Next
Cells(lig1, 6) = "=SUM(" & Mid(x, 2) & ")"
End Sub
Private Sub CommandButton3_Click() 'Ligne
If Cells(ActiveCell.Row, 1) Like "Phase*" Or Cells(ActiveCell.Row, 2) Like "Sous-phase*" Then Exit Sub
Dim n&
n = Cells(ActiveCell.Row, 2).End(xlUp).Row
Cells(ActiveCell.Row, 1).Resize(, 7).Interior.Color = RGB(242, 242, 242) 'gris clair
Cells(n, 6) = "=SUBTOTAL(9," & Cells(n + 1, 6).Resize(ActiveCell.Row - n).Address(0, 0) & ")"
End Sub
Private Sub Worksheet_SelectionChange(ByVal Targzt As Range)
CommandButton1.Top = ActiveCell.Top
CommandButton2.Top = ActiveCell.Top
CommandButton3.Top = ActiveCell.Top
End Sub