I will assume for simplicity that your raw data is in sheet1, and you want the output in sheet2, starting at A1 and going down. This is ideally a VBA project, but you have asked for a formula version - this is possible, but the more dynamic your data is (changing columns, changing row lengths, etc.), the more complicated this will be.
First, on sheet2 you will need to identify which columns hold your data. So in column D starting at D1 and going down, manually type those columns in, like so:
="A:A"
="B:B"
="E:E"
Beside each of those columns, you will want a count of how many rows are in each. Do this using the COUNTA function, which counts all non-blank cells [I am assuming that your data in sheet1 is continous, with no empty rows]. We will also use the INDIRECT function to determine which column to look at. So put this in E1, and drag down:
=COUNTA(INDIRECT("'Sheet1'!"&B1))
Then we want a running total of how many rows we have so far, one column after the other. Put this in F2 and drag down[F1 hardcode as 0]:
=SUM($E$1:E1)+.01
In Column B, we will now show which column that row's data is being pulled from, like so [starting in B1 and copied down]:
=INDEX(D:D,MATCH(ROW(),F:F,1))
In Column C, we will now show which row the data will be pulled from [starting in C1 and copied down]:
=COUNTIF($B$1:B1,B1)
In A1 and dragged down for as many total cells as you have data in, put the following [starting in A1, and dragged down]:
=INDEX(INDIRECT("'Sheet1'!"&B1),C1)
This looks like a lot of set-up - because it is. A lot of data manipulation is required if you aren't using VBA for something like this.