Hi, see attached.
[J7]=IF(ROW(J1)<=COUNTIF($D$5:$D$18;$J$4),INDEX(C$5:C$18,AGGREGATE(15,6,(ROW($C$5:$C$18)-4)/($D$5:$D$18=$J$4),ROW(J1))),"")
drag across and then delete the 2nd column (which is going to be the division).
In J7, copied across and down :
=IFERROR(INDEX($C:$F,AGGREGATE(15,6,ROW($C$5:$C$18)/($D$5:$D$18=$J$4),ROW(A1)),MATCH(J$6,$C$4:$F$4,0)),"")
View attachment 68190
A Pivot Table will do it in a couple of seconds
Another option
=FILTER(FILTER(C5:F18,D5:D18=J4),COLUMN(C5:F18)<>4)