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
| Sub tcd_vba()
Dim c As Integer, i As Integer, j As Integer
Dim deja As Boolean
Dim dercol As Integer, li As Integer, fin As Integer
Dim source As Range
Dim dest As Range, dest2 As Range
Set source = Range("C4") 'angle à gauche de la base de données
Set dest = Range("G4") 'angle à gauche du TCD
col = source.Column
c = dest.Column + 1
li = dest.Row
For i = li To source.Offset(1000, 1).End(xlUp).Row 'lecture des lignes
If Cells(li, c - 1) <> Cells(i, col) Then
Cells(li, c) = Cells(i, col) ' choix de date si non doublon
c = c + 1
End If
dercol = c
dest.Offset(1, 0) = source.Offset(0, 1) ' Premier élément equipe
deja = False
fin = dest.Offset(1000, 0).End(xlUp).Row
j = li + 1
While Not deja And j <= fin ' recherche doublon equipe
deja = Cells(j, dest.Column) = Cells(i, col + 1)
j = j + 1
Wend
If Not deja Then
Cells(fin + 1, dest.Column) = Cells(i, col + 1) 'nouvelle equipe
Cells(j, c - 1) = Cells(j, c - 1) + Cells(i, col + 2) 'prime '
fin = fin + 1
Else
Cells(j - 1, c - 1) = Cells(j - 1, c - 1) + Cells(i, col + 2) 'prime en plus '
End If
Next i
Set dest2 = dest.Offset(1, 0).Resize(fin - dest.Row, dercol - dest.Column) 'zone de tri des équipes
Feuil1.Sort.SortFields.Clear
dest2.Sort Key1:=dest, Order1:=xlAscending, Header:=xlGuess 'tri des équipes
End Sub |