Sorting list in Excel based on parameters


I’m trying to create a script which can place multiple parameter names and values in an Excel sheet. (Like in the Image below).

But it doesnt go the way I’d like yet. As you can see in the image, the category parameter is displayed twice but instead of splitting the list in an even way underneath both categories it puts all the values in one column and continues with the next value underneath the other category heading. This then ruins the order of all the other parameter values and names.

I also have another problem (see the image below).

The values in the orange squares belong to different elements and should be in the green squares (so in the same row as their element host). but instead of this it puts it at the top of the column.

I’ve added my script below.

Thanks in advance!