1 2 3 4 5 6 7 8 9 10 11
| Sub test()
Dim CEL1 As Range, CEL2 As Range, i As Long
Set CEL1 = [D5] 'on precise la premiere cellule en "D" contenant le mot"Montant" ou autre(c'est celle qui doit etre prise en compte pour le calcul somme de la premiere plage
For i = 5 To Cells(Rows.Count, "D").End(xlUp).Row
If Cells(i, "D") = "Total" Then
Set CEL2 = Cells(i - 1, "D")
Cells(i, "D").Offset(0, 2).Formula = "=SUM(" & Replace(Range(CEL1.Offset(0, 1), CEL2.Offset(0, 1)).Address, "$", "") & ")"
Set CEL1 = Cells(i + 1, "D")
End If
Next
End Sub |
Partager