This is how I read your problem.
Sub test()
Dim a, b, i As Long, ii As Long, iii As Long
Dim maxRow As Long, maxCol As Long
a = Application.Trim(Sheets("sheet1").Cells(1).CurrentRegion.Value)
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For ii = 1 To UBound(a, 2)
If a(1, ii) = "" Then maxCol = ii - 1: Exit For
b(1, ii) = a(1, ii)
For i = 2 To UBound(a, 1)
For iii = UBound(a, 2) To 2 Step -1
If a(i, iii - 1) = a(1, ii) Then
b(i, ii) = a(i, iii): Exit For
End If
Next iii, i
Next
With Sheets("sheet2").Cells(1).Resize(UBound(a, 1), maxCol)
.CurrentRegion.ClearContents
.Value = b
End With
End Sub
Bookmarks