Given two columns, Insert a value at a specific position in excel

Situation:

Screenshot of cells

I have two columns A and B. I want the third column C based on the position (specified by B) of the values (specified by A). For empty cells in C, I want to have 0.

How can I do this in Excel?

I tried with INDEX and VLOOKUP functions, but without success.


Maybe this is what you want. Please confirm.

Sample data is in Cells A1:C8. Row 1 is the header.

The formula in C2 is

=IFERROR(INDEX($A$2:$A$6,MATCH((ROW()-ROW($D$1)),$B$2:$B$6,0)),0)

Drag it down along the length of the intended rows. Since the data starts in Row 2, ROW () - ROW ($D$1) starts the Index with 1 and further for the MATCH Function. It can be changed to ROW() - ROW($C$1) too. Just need a constant 1. To simplify it you may use below as long as your data always starts in row 2.

=IFERROR(INDEX($A$2:$A$6,MATCH((ROW()-1),$B$2:$B$6,0)),0)

Depending upon your regional settings you might need to replace comma in the formula with semicolon.

enter image description here