Skip to content Skip to sidebar Skip to footer

Transpose N Rows To One Column In Google Sheets - Script Editor

I would like a custom function to transpose a large number of rows into one single column please. Small example (the actual one has thousands of rows) Desired result

Solution 1:

function rowstocolumn() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet2');
  const osh = ss.getSheetByName('Sheet3');
  const vs = sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn()).getValues();
  let col = [];
  vs.forEach(r => {
    r.forEach(c => col.push([c]))
  });
  osh.clearContents();
  osh.getRange(1,1,col.length,col[0].length).setValues(col);
}

Post a Comment for "Transpose N Rows To One Column In Google Sheets - Script Editor"