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
| Sub DoublonsConcatene()
Const Cct = "_": Const Entete = 3: Const ResCol = 5 'Gestion : Caractère de concaténation des col , Entete, nb de col à concaténer
Dim Rg As Range, VA(), i&, Coll As New Collection, R&, K$, S$, Db, V, L&
Set Rg = Feuil1.UsedRange.Rows
VA = Rg.Columns(1).Resize(, ResCol).Value
For i = 1 + Entete To UBound(VA)
For j = 2 To UBound(VA, 2)
VA(i, 1) = VA(i, 1) & Cct & VA(i, j)
Next
Next
ReDim Preserve VA(1 To UBound(VA), 1 To 1)
On Error Resume Next
For R = 1 + Entete To UBound(VA)
K = CStr(VA(R, 1))
Coll.Add R, K
If Err.Number = 457 Then
S = Coll(K) & Cct & R: Coll.Remove K: Coll.Add S, K, 1
Err.Clear
End If
Next
On Error GoTo 0
Feuil2.UsedRange.Clear
Application.ScreenUpdating = False
For Each Db In Coll
If IsNumeric(Db) Then
Exit For
Else
For Each V In Split(Db, Cct)
L = L + 1
Feuil2.Cells(L, 1).Resize(, Rg.Columns.Count).Value = Rg(V).Value
Feuil2.Cells(L, Rg.Columns.Count + 1).Resize(, 2).Value = Array(V, Mid(Rg(V).Cells(1).Value, 4))
Next
End If
Next
Application.ScreenUpdating = True
Set cRow = Nothing: Set Rg = Nothing
If L Then
With Feuil2.UsedRange.Columns
'.Sort .Cells(1), xlAscending, Header:=xlNo 'Mettre le code adequat pour le tri (ici sur la col 1)
Application.Goto .Cells(1), True
End With
Else
MsgBox "Aucun doublons trouvés", , "Recherches des doublons et tri": Exit Sub
End If
Inter_Coul_Doublons 'macro permetant de différencié les doublons surtout quand ils sont nombreux
End Sub |
Partager