Using your last sheet insert the following
array formula in B5
Code:
=IFERROR(INDEX($A$2:$LZ$2,SMALL(IF($A$1:$LZ$1=$A5,COLUMN($A$1:$LZ$1)),COLUMN(A:A)));"")
T
hen commit this formula with Ctrl+Shift+Enter
Next drag down and right as far as required.
It is possible that the calculations may take a little more time than usual.