Home > Blockchain >  script to copy some cells to last row of another spreadsheet at specific sheet?
script to copy some cells to last row of another spreadsheet at specific sheet?

Time:09-10

I have found script that can copy some specified rows to another sheet, which I manage to run successfully. However I want these rows to be copied to the end row of another spreadsheet. I've tried to find other posts so that to adjust these script but couldn't. So could you please help me. (I really have no idea about coding.)

function onOpen() {
SpreadsheetApp.getUi().createMenu('Copy to catalog')
.addItem('Copy Stuff', 'copyStuff')
.addItem('Create Sidebar', 'createSidebar')
.addToUi();
}

function copyStuff() {
     
var ss=SpreadsheetApp.getActive();
var ssh=ss.getSheetByName('multiple items'); 
var target= SpreadsheetApp.openById('1QaMmElzcCVVOeO8JD-3uCsuY2hkXAxb1x5d0heXcdWM');
var dsh = target.getSheetByName("catalog");
var lastRow = dsh.getLastRow();
var srg=ssh.getRange('A51:X54');

srg.copyTo(dsh.getRange(lastRow));

}

function createSidebar() {
 var html='<input type="button" value="Copy Stuff" onClick="jsCopyStuff();" />';
 html ='<script>function jsCopyStuff(){google.script.run.copyStuff();}</script>';
 var userInterface=HtmlService.createHtmlOutput(html);
 SpreadsheetApp.getUi().showSidebar(userInterface);
}

CodePudding user response:

Try:

function copyStuff() {
  var ss = SpreadsheetApp.getActive();
  var ssh = ss.getSheetByName('multiple items');
  var target = SpreadsheetApp.openById('1QaMmElzcCVVOeO8JD-3uCsuY2hkXAxb1x5d0heXcdWM');
  var dsh = target.getSheetByName("catalog");
  var lastRow = dsh.getLastRow();
  var vs = ssh.getRange('A51:X54').getValues();
  dsh.getRange(lastRow   1,1,vs.length,vs[0].length).setValues(vs);
}
  • Related