Merged cells are not a good thing....

Add a helper column in D2 of Sheet1 enter:

=LOOKUP(REPT("z",255),A$2:A2)&"^"&LOOKUP(REPT("z",255),B$2:B2)

and in E2 enter:

=D2&"_"&COUNTIF(D$2:D2,D2)

copy both down the rows.

Then in C2 of Sheet2, enter:

=IFERROR(INDEX(Sheet1!$C:$C,MATCH($B2&"^"&$A2&"_"&COLUMNS($A$1:A$1),Sheet1!$E:$E,0)),"")

copied down the rows and across as many columns as you wish.