Search code examples
javascriptgoogle-sheetscopy-pastegoogle-sheets-api

Copy a raw from sheet 'source' to another sheet 'destination' adding the date in the first column of the row Google spreadsheet


hey i would like to create a script that copy a row from a sheet to an other sheet each time i start the function so it will take the range of (H35:N35) sheet 'Bilan' and paste it in the first empty row of a column except the column 'A' in sheet "Stock", the column 'A' will be used to write the Date (its for backing up the stocks of some goods each week ) the result is that i will get: Date of the first week | the stock row Date of the second week`| the stock row

I edited some scripts to work but i didn't succeed so am looking for your help

Thank You


Solution

  • Here you go. It's pretty simple it copys from Bilan!H35:N35 to the first empty row of Stock and it starts in column B for the full length of the input range.

    function rangeCopy()
    {
      var ss=SpreadsheetApp.getActive();
      var sh1=ss.getSheetByName('Bilan');
      var sh2=ss.getSheetByName('Stock');
      var rg1=sh1.getRange('H35:N35');
      var rg2=sh2.getRange(sh2.getLastRow()+1,2,1,rg1.getWidth());
      rg1.copyTo(rg2);
    }