How to re-arrange and format excel dynamically using uipath

Hi guys,

I need some help to format an excel file using uipath, the bot has to re-arrange some cells to the correct column. The input excel file is like a (Parent Child structure) and the input varies every time. The bot has to read the column1 from the last cell value and go to the first cell value and then re-arrange it according to the column.

This is the input excel: exipup

FYI: here Major is parent of the corresponding child(Series) and ATC is the Parent of the corresponding child(Major), like this it goes up till DS.

And the desired output must be like this: excelop

If this can be done by hard coding, please help guys.

FYI: sometimes the Series and Major can change(like there can be 3 or 2)

Thank you in advance.