This macro might do it.
Sub Test()
Cells(1, 5) = "X"
For N = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Application.CountIf(Range(Cells(1, 6), Cells(1, Columns.Count)), Cells(N, 1)) = 0 Then
Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1) = Cells(N, 1)
End If
TargetColumn = Range(Cells(1, 6), Cells(1, Columns.Count)).Find(Cells(N, 1), , xlValues, xlWhole).Column
If Application.CountIf(Range(Cells(2, 5), Cells(Rows.Count, 5)), Cells(N, 2)) = 0 Then
NewGroupRow = Cells(Rows.Count, 5).End(xlUp).CurrentRegion.Row + Cells(Rows.Count, 5).End(xlUp).CurrentRegion.Rows.Count + 1
Cells(NewGroupRow, 5) = Cells(N, 2)
End If
TargetRow = Range(Cells(2, 5), Cells(Rows.Count, 5)).Find(Cells(N, 2), , xlValues, xlWhole).Row
Do While Cells(TargetRow, TargetColumn) <> ""
TargetRow = TargetRow + 1
Loop
Cells(TargetRow, TargetColumn) = Cells(N, 3)
Next N
End Sub
I've assumed that your data starts in Cell A1 and it is sorted by Group number.
Bookmarks