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 44 45 46 47 48 49
| Option Explicit
Sub tykkle()
Dim i, j As Integer
Dim rng_ori As Range
Dim table()
Dim rd As Integer
Dim bool As Boolean
With Worksheets("Feuil1")
Set rng_ori = .Range("F2")
rd = 1
ReDim table(1 To 2, 1 To rd)
table(1, rd) = rng_ori
table(2, rd) = rng_ori.Offset(0, -1)
For i = 1 To .Columns(6).Find("*", , , , , xlPrevious).Row
If rng_ori.Offset(i, 0) <> "" Then
bool = True
For j = LBound(table, 2) To UBound(table, 2)
If rng_ori.Offset(i, 0) = table(1, j) Then
table(2, j) = table(2, j) + rng_ori.Offset(i, -1)
bool = False
End If
Next j
If bool Then
rd = rd + 1
ReDim Preserve table(1 To 2, 1 To rd)
table(1, rd) = rng_ori.Offset(i, 0)
table(2, rd) = rng_ori.Offset(i, -1)
End If
End If
Next i
End With
With Worksheets("Feuil2")
.UsedRange.ClearContents
.Range("A1") = "N° AFFAIRE"
.Range("B1") = "Total par AFF"
Set rng_ori = .Range("A1")
For i = LBound(table, 2) To UBound(table, 2)
rng_ori.Offset(i, 0) = table(1, i)
rng_ori.Offset(i, 1) = table(2, i)
Next i
End With
End Sub |
Partager