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 Remplissage()
Dim C As Range, Sem As Byte, DerLig As Byte
DerLig = Cells(Rows.Count, 1).End(xlUp).Row
For Each C In Range("A2", Cells(Rows.Count, 1).End(xlUp))
With C.Offset(, 1)
On Error Resume Next
If (Month(C.Value) <> Month(C.Offset(-1))) Then
For i = C.Row To DerLig
If Month(Cells(i, 1)) = Month(Cells(C.Row, 1)) Then
Sem = Sem + 1
Else
Exit For
End If
Next i
.Formula = "=AVERAGE(" & Cells(C.Row, 3).Address & ":" & _
Cells(C.Row + Sem - 1, 3).Address & ")"
.Offset(, 2).Formula = "=AVERAGE(" & .Offset(, 3).Address & ":" & _
.Offset(Sem - 1, 3).Address & ")"
.Offset(1).Formula = "=MAX(" & Cells(C.Row, 3).Address & ":" & _
Cells(C.Row + Sem - 1, 3).Address & ")"
.Offset(1, 2).Formula = "=MAX(" & .Offset(, 3).Address & ":" & _
.Offset(Sem - 1, 3).Address & ")"
.Offset(2).Formula = "=MIN(" & Cells(C.Row, 3).Address & ":" & _
Cells(C.Row + Sem - 1, 3).Address & ")"
.Offset(2, 2).Formula = "=MIN(" & .Offset(, 3).Address & ":" & _
.Offset(Sem - 1, 3).Address & ")"
End If
On Error GoTo 0
End With
Next C
End Sub |
Partager