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
| Dim tTab, lgPos As Variant, lgPos1 As Variant, dbTot As Variant, sItem As Variant
Application.ScreenUpdating = False
iRow = Range("A" & Rows.Count).End(xlUp).Row
iCol = Cells(1, Columns.Count).End(xlToLeft).Column
Range("A1").Resize(iRow, iCol).Sort key1:=Range("A2"), order1:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes
tTab = Range("A1").Resize(iRow + 1, iCol).Value
lgPos = 3
lgPos1 = 2
sItem = tTab(2, 1)
Do
If tTab(lgPos, 1) = sItem Then tTab(lgPos - 1, 1) = ""
If tTab(lgPos, 1) <> sItem Then
dbTot = 0
For y = lgPos1 To lgPos - 1
dbTot = dbTot + CDbl(tTab(y, UBound(tTab, 2)))
Next
tTab(lgPos - 1, UBound(tTab, 2)) = dbTot
lgPos1 = lgPos
sItem = tTab(lgPos, 1)
End If
lgPos = lgPos + 1
Loop Until lgPos > UBound(tTab, 1)
With Worksheets("Fusion de lignesl")
.Range("A1").Resize(iRow, iCol).Value = tTab
.Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete Shift:=xlUp
.Range("A1").CurrentRegion.Borders.LineStyle = xlContinuous
.Range("A1").Resize(1, iCol).Interior.ColorIndex = 15
.Columns.AutoFit
.Activate
End With |
Partager