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
| Sub test()
Dim offset As Long
Dim NbZero As Integer
Dim L As Long
Dim R As Range
Set R = ActiveSheet.UsedRange
NbZero = 3
For L = 2 To R.Rows.Count
If R(L, 2) <> 0 Then
If NbZero > 2 Then
If offset <> 0 Then
R(offset, 4).Formula = Replace("=""Cells(" & R(offset, 1).Address & ":" & R(L, 1).Address & ")=""&" & R(offset, 3).Address & " - " & R(L, 3).Address, "$", "")
offse2 = offset
End If
offset = L: R(offset, 3) = 0
End If
NbZero = 0
R(L, 3) = ""
R(offset, 3) = R(offset, 3) + R(L, 2)
Else
NbZero = NbZero + 1
R(L, 3) = ""
R(L, 4) = ""
End If
Next
If offset <> 0 And offset < L - 1 Then R(offset, 4).Formula = Replace("=""Cells(" & R(offset, 1).Address & ":" & R(L - 1, 1).Address & ")=""&" & R(offset, 3).Address & " - " & R(L - 1, 3).Address, "$", "")
MsgBox "Fin"
End Sub |
Partager