or even better for unsorted lists
using the dic will be the fastest
Option Explicit
Sub testp()
Dim a, b(), i As Long, n As Long, z As Long, y As Long, Dict1 As Object, Dict2 As Object, p As Long
With Range("a1", Range("a" & Rows.Count).End(xlUp)).Resize(, 2)
a = .Value
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 1))
Set Dict1 = CreateObject("Scripting.Dictionary")
Set Dict2 = CreateObject("Scripting.Dictionary")
With Dict1
.CompareMode = vbTextCompare
For i = 1 To UBound(a, 1)
a(i, 1) = Trim(a(i, 1))
If Not IsEmpty(a(i, 1)) Then
If Not .exists(a(i, 1)) Then
p = 2: n = n + 1
b(1, n) = a(i, 1)
.Add a(i, 1), n
With Dict2
.Add a(i, 1), p
End With
End If
b(Dict2.Item(a(i, 1)), .Item(a(i, 1))) = a(i, 2)
With Dict2
If .exists(a(i, 1)) Then
.Item(a(i, 1)) = .Item(a(i, 1)) + 1
End If
End With
y = IIf(Dict2.Item(a(i, 1)) > y, Dict2.Item(a(i, 1)), y)
End If
Next
End With
End With
Sheets("sheet2").Range("A1").Resize(y, n).Value = b
End Sub
Bookmarks