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
|
Sub test()
Dim Cell As Range
Dim i As Integer
Dim Un As New Collection
Dim cpt_agregat As Integer
Dim laDonnee As String
On Error Resume Next
'Recherche les doublons dans la plage A1:A15
For Each Cell In Range("A1:A11")
'Utilise la propriété "Key" des collections qui
'n'acceptent que des valeurs uniques.
Un.Add Cell, CStr(Cell)
Next Cell
On Error GoTo 0
For i = 1 To Un.Count
'Afiche le résultat sans doublon dans la colonne B
laDonnee = Un.Item(i)
cpt_agregat = 0
For Each Cell In Range("A1:A11")
If Cell.Value = laDonnee Then
cpt_agregat = cpt_agregat + 1
Cell.Value = laDonnee & "-" & cpt_agregat
End If
Next Cell
Cells(i, 2) = Un.Item(i)
Next i
End Sub |
Partager