简体   繁体   中英

How can I move a range from one Google sheet to the next blank row in a different sheet/tab

Forgive my ignorance, I am very new to this. I am trying to take a range of data from one sheet and paste it into the first blank row of a second sheet (in the same workbook). After the data has moved, I would like to clear the data from the first sheet.

The data is in a tab called 'attendance' and is column A through to E, from row 18 onwards (I don't need to bring in the headers in row 17). I am trying to paste it into a sheet called 'copy' in columns A through E - whatever the next blank cell is in A.

Where I am getting stuck is bringing over all the rows of data from the 'attendance' sheet. At the moment, I can only figure out how to bring over one row - but there might be dozens. Clearing the data seems to be working fine.

Here is the code I have so far:

function shiftandclear() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getRange("Attendance!A18:E");
  var destSheet = ss.getSheetByName("Copy);
  destSheet.appendRow(source.getValues()[0]);
  source.clear();
}

Many thanks for any help you can provide.

function shiftandclear() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Attendance');
  const vr = sh.getRange(18, 1, sh.getLastRow() - 17, 5);
  const vs = vr.getValues();
  var dsh = ss.getSheetByName("Copy");
  dsh.getRange(dsh.getLastRow() + 1, 1, vs.length, vs[0].length).setValues(vs);
  vr.clearContent();
}

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