Search code examples
google-sheetsgoogle-sheets-formulaarray-formulastranspose

How can I rearrange a Google Sheet using the data within the sheet?


I get massive serialized spreadsheets in the following format:

PN   SN  Qty
1    24   3
2    25   1
3    26   7

I need to write a Sheets script that can rearrange the data so that the headers are gone, and the quantities are extrapolated, then cleared.

For example, the desired result would be:

1  24
1  24
1  24
2  25
3  26
3  26
3  26
3  26
3  26
3  26
3  26

I have tried writing a few recursive statements to achieve this, however once I started adding in new rows to the sheet my loop breaks. I've tried hundreds of different iterations of what I know should be a fairly simple task but alas, I am well out of practice. I fear at this point I am fixated on the wrong idea. Any help in the right direction would be greatly appreciated!


Solution

  • You don't need to use google apps script.

    Try the following formula:

    ={ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
     REPT(A2:A&"♠", C2:C), ,999^99), "♠")))),ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
     REPT(B2:B&"♠", C2:C), ,999^99), "♠"))))}
    

    example