i'll try and post this and hope it doesn't wrap.
i assumed the data started in A1 on sheet1 and use sheet3 to do a sort. if this
is not the case or you don't have a sheet3, then it will have to be modified.
Option Explicit
Sub Macro1()
Dim ws As Worksheet
Dim lastcol As Long
Dim lastrow As Long
Dim x As Long, z As Long, w As Long, y As Long
Dim i As Long, n As Long, k As Long
Dim arr() As Variant
Dim arr2() As Variant
Dim arr3() As Variant
Dim cell As Range
Dim lastrow3 As Long
Dim ws3 As Worksheet
Set ws = Worksheets("Sheet1")
Set ws3 = Worksheets("Sheet3")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
lastcol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
For x = 2 To lastrow Step 3
ReDim Preserve arr(0 To z)
arr(z) = ws.Range("A" & x - 1 & ":" & Cells(x, lastcol).Address)
z = z + 1
Next
z = 0
For i = LBound(arr) To UBound(arr)
ReDim Preserve arr2(0 To z)
ReDim Preserve arr3(0 To z)
arr2(z) = arr(i)(2, lastcol)
arr3(z) = arr(i)(1, 1)
z = z + 1
Next i
y = 1
For w = LBound(arr) To UBound(arr)
ws3.Range("A" & w + 1).Value = arr(w)(1, 1)
ws3.Range("B" & w + 1).Value = Application.Max(arr(w))
Next
With ws3.Columns("A:B")
.Sort Key1:=.Range("B1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
lastrow3 = ws3.Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In ws3.Range("A1:A" & lastrow3)
Do While cell.Value <> arr(n)(1, 1)
n = n + 1
Loop
ws.Range("A1:" & Cells(2, lastcol).Address).Offset(k) = arr(n)
ws.Cells(2, lastcol).Offset(k).Formula = "=sum(" & _
ws.Range("B2").Offset(k).Address & ":" & ws.Cells(2, lastcol - _
1).Offset(k).Address & ")"
k = k + 3
n = 0
Next
ws3.Cells.Clear
End Sub