Try,
1] Helper column F, F2 formula copy down :
=IF((4-SUM(COUNTIF(B2:E2,{""," "})))>0,MAX(F$1:F1)+1,"")
2] G2 formula copy down :
=IFERROR(INDEX(A$2:A$20,MATCH(ROWS($1:1),F$2:F$20,0)),"")
3] H2 formula copy across and down :
=IF(G2="","",INDEX($B$2:$E$20,MATCH($G2,$A$2:$A$20,0),MATCH(H$1,$B$1:$E$1,0)))
Regards
Bosco