Google Apps Script - How to copy a column(s) to another sheet at next available column

后端 未结 3 1015
庸人自扰
庸人自扰 2020-12-21 17:58

I have a requirement where I need to take values from one column (or more) and copy them to another sheet in the next available column (s). I have written a script like this

3条回答
  •  误落风尘
    2020-12-21 18:40

    The entire 4th column & 17th row onward can be appended as a column into a different sheet with this approach also.

      var sheetfrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheetfrom');
      var sheetto = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheetto');
    
      sheetfrom.getRange(17, 4, sheetfrom.getLastRow(), 1).copyTo(sheetto.getRange(1, 
      sheetTo.getLastColumn()+1, sheetfrom.getLastRow()-17, 1), {
        contentsOnly: true
      });
    

    This also overcomes the empty cell problem of copying data from some Formula outputs.

提交回复
热议问题