Public Hauteur As Integer
Sub gestion_des_doublons()
DerLig = Range("B" & Rows.Count).End(xlUp).Row
Range("B9:E" & Hauteur).Value = Charge(Range("B9:B" & DerLig))
Range("B" & Hauteur + 1 & ":E" & DerLig).ClearContents
End Sub
Function Charge(MaRéf As Range)
'Dictionary par JB : http://boisgontierjacques.free.fr/ Formation Excel VBA JB
Dim Tableau()
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In MaRéf
MonDico.Item(c.Value) = c.Value
Next c
temp = MonDico.items
'--
Call tri(temp, LBound(temp), UBound(temp))
Hauteur = UBound(temp) + 9
ReDim Tableau(UBound(temp), 3)
For I = 0 To UBound(temp)
Tableau(I, 0) = temp(I)
Tableau(I, 1) = MaRéf.Find(temp(I), LookAt:=xlWhole).Offset(0, 1)
Tableau(I, 2) = Evaluate("COUNTIF(" & MaRéf.Address & ",""" & temp(I) & """)")
Tableau(I, 3) = MaRéf.Find(temp(I), LookAt:=xlWhole).Offset(0, 3)
Next I
Charge = Tableau
End Function
Sub tri(a, gauc, droi)
' Quick sort par JB : http://boisgontierjacques.free.fr/ Formation Excel VBA JB
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub