简体   繁体   中英

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

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);
}

Thanks For the help Cooper ,and for adding the date to the first cell in each pasted raw i used this :

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



function  DateNow()
{
  var sss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Backup');
  var date = new Date; 
  var RangeIndex = sss.getLastRow() ;
  sss.getRange('A'+ RangeIndex).setValue(date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear());
}

function onOpen()
{
    SpreadsheetApp.getUi()
        .createMenu('Custom Menu')
        .addItem('Transfer Row', 'start')
        .addToUi()
}
function start() 
{
rangeCopy()
DateNow()

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM