Try
Sub test()
Dim a, i As Long, ii As Long, w, txt As String, e, n As Long, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
With Sheets("sheet1").Cells(1).CurrentRegion
For ii = 1 To .Columns.Count
If Application.CountA(.Columns(ii).Offset(1)) Then txt = txt & "," & ii
Next
a = Application.Index(.Value, Evaluate("row(1:" & .Rows.Count & _
")"), Split(Mid$(txt, 2), ",")): txt = ""
End With
For i = 2 To UBound(a, 1)
For ii = 4 To UBound(a, 2)
txt = txt & Chr(2) & a(i, ii)
Next
If Not dic.exists(txt) Then
ReDim w(1 To UBound(a, 2), 1 To 1)
Else
w = dic(txt)
ReDim Preserve w(1 To UBound(a, 2), 1 To UBound(w, 2) + 1)
End If
For ii = 1 To UBound(a, 2)
w(ii, UBound(w, 2)) = a(i, ii)
Next
dic(txt) = w: txt = ""
Next
With Sheets("sheet2").Cells(1).Resize(, UBound(a, 2))
.CurrentRegion.EntireColumn.ClearContents
.Rows(1).Value = a: n = 1
For Each e In dic
n = n + 1
.Rows(n).Resize(UBound(dic(e), 2)).Value = Application.Transpose(dic(e))
n = n + UBound(dic(e), 2)
Next
End With
End Sub
Bookmarks