G2:
=IFERROR(IF(COUNTIF($G$1:G1,G1)<COUNTA(OFFSET($A$1,MATCH(G1,$A$1:$A$4,0)-1,1,1,4)),G1,OFFSET($A$1,MATCH(G1,$A$1:$A$4,0),0,1,1)),"")
複製到G3:G11,若超過G12為顯示0,可以不要複製到2列或設定G欄不顯示0。
H2:
=IFERROR(IF(COUNTIF($G$2:G2,G2)<=COUNTA(OFFSET($A$1,MATCH(G2,$A$2:$A$4,0),1,1,4)),VLOOKUP(G2,$A$2:$E$4,COUNTIF($G$2:G2,G2)+1,0)),"")
複製到H3:H11。