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 33 34 35 36 37 38 39 40 41 42 43
| Sub Sakarov()
Dim TheCel As Range
Dim FirstCel As Range
Dim TheSh As Worksheet
Dim LFirstCel As Long, LLastCel As Long
Set TheSh = Sheets("Feuil1")
With TheSh
Set FirstCel = .Range("A2")
Do
For Each TheCel In .Range(FirstCel.Offset(1, 0), .Cells(Rows.Count, "A").End(xlUp).Offset(1, 0))
If FirstCel.Value <> TheCel.Value Then
LFirstCel = FirstCel.Row
LLastCel = TheCel.Offset(-1, 0).Row
FirstCel.Offset(0, 11).Value = WorksheetFunction.SumProduct(.Range(.Cells(LFirstCel, "J"), .Cells(LLastCel, "J")), .Range(.Cells(LFirstCel, "E"), .Cells(LLastCel, "E"))) / WorksheetFunction.SumProduct(.Range(.Cells(LFirstCel, "K"), .Cells(LLastCel, "K")), .Range(.Cells(LFirstCel, "E"), .Cells(LLastCel, "E")))
FirstCel.Offset(0, 12).Formula = "=SumProduct(" & .Range(.Cells(LFirstCel, "J"), .Cells(LLastCel, "J")).Address & "," & .Range(.Cells(LFirstCel, "E"), .Cells(LLastCel, "E")).Address & ")/ SumProduct(" & .Range(.Cells(LFirstCel, "K"), .Cells(LLastCel, "K")).Address & "," & .Range(.Cells(LFirstCel, "E"), .Cells(LLastCel, "E")).Address & ")"
Exit For
End If
Next TheCel
Set FirstCel = TheCel
Loop Until FirstCel.Value = ""
End With
End Sub |
Partager