Skip to content
Advertisement

Google Appscript transpose dynamic data group from one column

I’ve been jogging my brain trying to figure out how to write this script to transpose data from one sheet to another from a pretty dirty sheet.

There are other questions like this but none seem to be like my particular use case.

This is how the sheet is currently structured (somewhat):

enter image description here

The biggest issue here is I have no concrete idea how many rows a particular group of data will be, But I know there are always a bunch of blank rows between each group of data.

I found a script that took me half way:

JavaScript

But in that case the asker dataset was fixed. I can loosely say that the max number of rows each group would have is 10(this is an assumption after browsing 3000 rows of the sheet…but if the script can know this automatically then it would be more dynamic). So with that in mind…and after butchering the script…I came up with this…which in no way works how it should currently(not all the data is being copied):

JavaScript

I’m pretty sure I should maybe still be using array.splice() but haven’t been successful trying to implement it achieve what i want, here’s how the transposed sheet should look:

enter image description here

Info:

  • Each group of addresses inside the “copyfrom” sheet would be separated by at least 1 blank line
  • The length of an address group is not static, some can have 5 rows, others can have 8, but address groups are always separated by blank rows

Any help is appreciated

Advertisement

Answer

You are right to iterate all input values, and I can suggest the similar code:

JavaScript
Advertisement