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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| Sub test()
'======================================================================
'on fait un trie pour etre sur
Columns("A:B").Select
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range( _
"A2:A" & Range("A" & Rows.Count).End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveSheet.Sort
.SetRange Range("A1:B" & Range("A" & Rows.Count).End(xlUp).Row)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'======================================================================
'on crée une nouvelle colonne temporaire pour avoir une clé integer
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
'=======================================================================
'on affecte numéro pour clé
Dim No_clé As Integer
No_clé = 1
For i = 2 To Range("B" & Rows.Count).End(xlUp).Row
If Cells(i, 2).Value = Cells(i + 1, 2).Value Then
Cells(i, 1).Value = No_clé
Else
Cells(i, 1).Value = No_clé
No_clé = No_clé + 1
End If
Next
'=======================================================================
'on fait une boucle
For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
'si la cellule est identique à la suivante
If Cells(i, 1).Value = Cells(i + 1, 1).Value Then
'on filtre
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$C$" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter Field:=1, Criteria1:=Cells(i, 1).Value
Ligne_i = i
colonne = 3
Dim MaPlage As Range
Set MaPlage = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible)
Dim Ligne As Range, PrecVal As Variant
'on passe ligne à ligne le filtre
For Each Ligne In MaPlage.Rows
If Ligne.Row <> 1 Then
'écriture des donné
Cells(Ligne_i, colonne).Value = Ligne.Cells(3).Value
colonne = colonne + 1
i = i + 1
End If
Next
End If
Next
'================================================================
'on enleve le filtre
ActiveSheet.Range("$A$1:$B$" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter Field:=1
'=================================================================
'on supprime la colonne temporaire créer au début
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
'=====================================================================
'on supprime les doublons
MaCellule = ("A2")
Range(MaCellule).Select
ActiveCell.CurrentRegion.Sort Key1:=Range(MaCellule), Order1:=xlAscending, Header:=xlYes
donnee1 = ActiveCell
ActiveCell.Offset(1, 0).Select
While ActiveCell <> ""
If ActiveCell = donnee1 Then
ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select
donnee1 = ActiveCell
ActiveCell.Offset(1, 0).Select
Else
donnee1 = ActiveCell
ActiveCell.Offset(1, 0).Select
End If
Wend
'======================================================================
MsgBox "fin"
End Sub |
Partager