1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| Sub Calcul()
Dim X As Integer, Y As Integer, MoisEch As Byte, MoisObs As Byte, An As Integer
Dim inCalculationMode As Integer, Sh As Worksheet, Plage As Range
Dim Plg As Range
Application.ScreenUpdating = False
inCalculationMode = Application.Calculation
' Application.Calculation = xlCalculationManual
Set Sh = Sheets("Feuil2")
With Sheets("Feuil2")
Set Plage = .Range(.[G1], .Cells(.Rows.Count, 7).End(xlUp)).Resize(, 4)
End With
With Sheets("Feuil1")
.[C4:S20].ClearContents
For X = 4 To .Cells(.Rows.Count, 2).End(xlUp).Row
For Y = 3 To .Cells(3, .Columns.Count).End(xlToLeft).Column
MoisEch = Month(.Cells(X, 2))
MoisObs = Month(.Cells(3, Y))
An = Year(.Cells(3, Y))
Sh.AutoFilterMode = False
Plage.AutoFilter 1, "<=" & MoisObs
Plage.AutoFilter 2, "<=" & An
Set Plg = Plage.Offset(1).Resize(Plage.Rows.Count - 1)
If Application.Subtotal(103, Plg) > 0 Then
.Cells(X, Y) = Application.Subtotal(109, Plg.Resize(, 1).SpecialCells(xlCellTypeVisible).Offset(, 2)) _
/ Application.Subtotal(109, Plg.Resize(, 1).SpecialCells(xlCellTypeVisible).Offset(, 3)) * -1
End If
Next Y
Next X
End With
Application.Calculation = inCalculationMode
Application.ScreenUpdating = True
End Sub |
Partager