Try this on a small amount of data first:-
Results on sheet1
Sub MG18Apr08
Dim Dic As Object
Dim rDn As Long
Dim Q
Dim nRay()
Dim Ray
Dim c As Long
Dim Nam As String
Dim Col As Integer
Dim n As Long
Dim Omax As Long
Dim ColNum As Integer
ColNum = 1
Ray = Cells(1).CurrentRegion.Value
For Col = 2 To 4
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = 1
For rDn = 2 To UBound(Ray, 1)
If Not Dic.exists(Ray(rDn, 1)) Then
Set Dic(Ray(rDn, 1)) = CreateObject("Scripting.Dictionary")
End If
If Not Dic(Ray(rDn, 1)).exists(Ray(rDn, Col)) Then
Dic(Ray(rDn, 1))(Ray(rDn, Col)) = Ray(1, Col)
End If
Next rDn
Dim k As Variant
Dim p As Variant
Dim Tg As Integer
Dim Tem As Integer
c = 1
For Each k In Dic.keys
c = c + 1
n = IIf(Col = 2, 1, 0)
For Each p In Dic.Item(k)
n = n + 1
Tg = IIf(Col = 2, n - 1, n)
If n >= Tem Then ReDim Preserve nRay(1 To Dic.Count + 1, 1 To n)
If Col = 2 Then nRay(c, 1) = k: nRay(1, 1) = "nAME"
nRay(1, n) = Dic(k).Item(p) & Tg
nRay(c, n) = p
Tem = UBound(nRay, 2)
Next p
Omax = Application.Max(Omax, n)
Next k
Sheets("Sheet1").Cells(1, ColNum).Resize(c, Omax) = nRay
ColNum = ColNum + Omax
Omax = 0
Erase nRay
Tem = 0
Next Col
End Sub
Regards Mick
Bookmarks