Try this
Sub test()
Dim a, i As Long, ii As Long, txt As String, n As Long, maxCol As Long, w
a = Sheets("sheet1").Cells(1).CurrentRegion.Value
ReDim Preserve a(1 To UBound(a, 1), 1 To UBound(a, 2) + 100)
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 1 To UBound(a, 1)
txt = Join(Array(a(i, 1), a(i, 2), a(i, 3), a(i, 4)), Chr(2))
If Not .exists(txt) Then
n = n + 1: .Item(txt) = VBA.Array(n, 4)
For ii = 1 To 4
a(n, ii) = a(i, ii)
Next
End If
w = .Item(txt): w(1) = w(1) + 1
If w(1) > UBound(a, 2) Then
ReDim Preserve a(1 To UBound(a, 1), 1 To UBound(a, 2) + 100)
End If
a(w(0), w(1)) = a(i, 5)
.Item(txt) = w
maxCol = Application.Max(maxCol, w(1))
Next
End With
With Sheets.Add().Cells(1).Resize(n, maxCol)
.Value = a
.Columns.AutoFit
End With
End Sub
Bookmarks