Sub test()
Dim sortArray As Object
Dim tempDic As Object, colDic As Object
Dim lRow As Long
Dim cel As Range
Set sortArray = CreateObject("System.Collections.ArrayList")
Set tempDic = CreateObject("Scripting.Dictionary")
lRow = Cells(Rows.Count, 4).End(xlUp).Row - 1
Cells(1, 1).Resize(lRow + 1, 3).Copy Sheets("Output").Cells(1, 1)
For Each cel In Range("D1:O1")
tempDic.Add Item:=Range(cel, cel.Offset(lRow)), Key:=cel.Value
sortArray.Add cel.Value
Next
sortArray.Sort
Set colDic = CreateObject("Scripting.Dictionary")
For i = 0 To sortArray.Count - 1
colDic.Add Item:=tempDic.Item(sortArray(i)), Key:=sortArray(i)
Next
i = 4
For Each Key In colDic.Keys
colDic.Item(Key).Copy Sheets("Output").Cells(1, i)
i = i + 1
Next
Set sortArray = Nothing
Set tempDic = Nothing
Set colDic = Nothing
End Sub