Salut le forum,
un essai et adapter
Option Explicit
Sub SupprDoublonsTrier()
Dim A As Range, Where As Range
Dim sh As Worksheet, Data
Set sh = ActiveWorkbook.Worksheets("Feuil1")
sh.Sort.SortFields.Clear
sh.Sort.SortFields.Add Key:=Range("A2:AO2") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With sh.Sort
.SetRange Range("B2", Range("AO" & Rows.Count).End(xlUp))
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
For Each A In Range("B2", Range("B" & Rows.Count).End(xlUp))
Set Where = Intersect(A.EntireRow, Range("B:AO"))
Data = UniqueItems(Where, vbTextCompare)
Where.ClearContents
Where(1).Resize(, UBound(Data) + 1).Value = Data
Next
End Sub
Private Function UniqueItems(ByVal r As Range, _
Optional ByVal Compare As VbCompareMethod = vbBinaryCompare, _
Optional ByRef Count) As Variant
'Return an array with all unique values in R
' and the number of occurrences in Count
Dim Area As Range, Data
Dim i As Long, j As Long
Dim Dict As Object 'Scripting.Dictionary
Set r = Intersect(r.Parent.UsedRange, r)
If r Is Nothing Then
UniqueItems = Array()
Exit Function
End If
Set Dict = CreateObject("Scripting.Dictionary")
Dict.CompareMode = Compare
For Each Area In r.Areas
Data = Area
If IsArray(Data) Then
For i = 1 To UBound(Data)
For j = 1 To UBound(Data, 2)
If Not Dict.Exists(Data(i, j)) Then
Dict.Add Data(i, j), 1
Else
Dict(Data(i, j)) = Dict(Data(i, j)) + 1
End If
Next
Next
Else
If Not Dict.Exists(Data) Then
Dict.Add Data, 1
Else
Dict(Data) = Dict(Data) + 1
End If
End If
Next
UniqueItems = Dict.Keys
Count = Dict.Items
End Function
@++