Bonjour à tous,
Un peu tordu aussi :
Sub test()
Dim r As Range, j As Byte
Application.ScreenUpdating = False
With Sheets(1)
.Columns(1).Insert
With .Range("a2:a" & .Range("b" & Rows.Count).End(xlUp).Row)
.Formula = "=if(and(c1&d1<>c2&d2),if(a1=1,""a"",1),"""")"
.Value = .Value
On Error Resume Next
.SpecialCells(2, 1).EntireRow.Insert
.SpecialCells(2, 2).EntireRow.Insert
On Error GoTo 0
End With
.Columns(1).Delete
For Each r In Columns(2).SpecialCells(2, 1).Offset(, -1).Areas
r(r.Count + 1, 1) = r(r.Count, 1): r(r.Count + 1, 2) = r(r.Count, 2)
r(r.Count + 1, 3) = r(r.Count, 3): r(r.Count + 1, 4) = "2022-2021"
Select Case r.Count
Case Is = 2
For j = 5 To 17
r(r.Count + 1, j).Value = r(r.Count, j) - r(r.Count - 1, j)
Next
Case Is = 1
Select Case r(r.Count, 4)
Case 2022
For j = 5 To 17
r(r.Count + 1, j).Value = -r(r.Count, j)
Next
Case 2021
For j = 5 To 17
r(r.Count + 1, j).Value = r(r.Count, j)
Next
End Select
End Select
Next
If Application.WorksheetFunction.CountA(Range("2:2")) = 0 Then
.Rows(2).Delete
End If
End With
Application.ScreenUpdating = True
End Sub
klin89