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
| Sub test()
Dim Zone As Range, C, Depart As String
Dim MonDico As Object
Dim Cel As Range, Rng As Range, Rng2 As Range
Dim i As Integer
With Worksheets(1)
With .Range("A1:B" & .Cells(.Rows.Count, 1).End(xlUp).Row)
.AutoFilter
.AutoFilter Field:=2, Criteria1:="EVR"
End With
End With
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set Rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 6) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If Rng2 Is Nothing Then
MsgBox "No data to copy"
Exit Sub
Else
Set MonDico = CreateObject("Scripting.Dictionary")
Set Zone = Intersect(Rng2, [A:A])
MsgBox "Zone : " & Zone.Address
' -- Noms sans doublons
For Each Cel In Zone
If Not MonDico.Exists(Trim(Cel.Value)) Then MonDico.Add Trim(Cel.Value), Trim(Cel.Value)
Next Cel
For Each C In MonDico.Keys
Set Cel = Zone.Find(what:=Trim(C), LookIn:=xlValues, lookat:=xlPart)
If Not Cel Is Nothing Then
Depart = Cel.Address
i = i + 1
Do
MsgBox "Cel : " & Cel & ", ligne i : " & i
Set Cel = Zone.FindNext(C)
Loop While Not Cel Is Nothing And Depart <> Cel.Address
End If
Next C
End If
ActiveSheet.ShowAllData
End Sub |
Partager