Sub Demo1()
Dim Rg As Range
Application.ScreenUpdating = False
L& = 3
With Sheet1
.Cells(4).CurrentRegion.Clear
Set Rg = .Cells(1).CurrentRegion.Rows
Rg("2:3").Copy .[D2]
For R& = 4 To Rg.Count
If Rg.Cells(R, 1).Value <> Rg.Cells(R - 1, 1).Value Then
L = L + 1: Rg(R).Copy .Cells(L, 4)
ElseIf Rg.Cells(R, 2).Value <> Rg.Cells(R - 1, 2).Value Then
C& = .Cells(L, 4).End(xlToRight).Column + 1
Rg.Cells(R, 2).Copy .Cells(L, C)
If .Cells(2, C).Value = "" Then .Cells(2, C - 1).Copy .Cells(2, C)
End If
Next
End With
Set Rg = Nothing
End Sub