In general these are generally best resolved using helpers to keep things efficient...
Using your sample file
D5: =$A5&":"&$B5
copied down
At which point, once you set your headers in row 20 such that they match the source values (ie Subject1 rather than Subject 1) then:
B21: =LOOKUP(REPT("Z",255),CHOOSE({1,2},"",INDEX($C$5:$C$14,MATCH($A21&":"&B$20,$D$5:$D$14,0))))
copied across matrix
You could as implied do without helpers, you could also achieve same output using VBA - you don't really specify preference(s).
On an aside you can reduce no. of calcs based on the max 5 subject rule along the lines of:
B21: =IF(COUNTIF($A21:A21,"*?")=6,"",LOOKUP(REPT("Z",255),CHOOSE({1,2},"",INDEX($C$5:$C$14,MATCH($A21&":"&B$20,$D$5:$D$14,0)))))
copied across matrix
Bookmarks