简体   繁体   中英

Insert new row at top of sheet based on new rows in another tab

I have a Google sheet with a listing of job candidates in one tab (Primary candidates sheet). What I would like to do is paste a daily export of candidates into another tab and have new candidates from the latest export inserted up top of the primary candidates sheet.

I've tried to search this methodology online which typically leads to success after some research. However, I can't seem to find any documentation on macros, scripts, or formulas which could accomplish this.

Wanted to see if anyone had any resources for additional research.

You can use below code to copy data from source sheet into top of destination sheet. Enter sheet names accordingly. Save. From script editor menu, Run > Function > Test , to test. It'll insert new rows in destination sheet and source sheet data will stay as is.

function test() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getSheetByName('source sheet name here'); // change here
  var des = ss.getSheetByName('destination sheet name here'); // change here

  var sv = source
    .getDataRange()
    .getValues();
  sv.shift();
  des.insertRowsAfter(1, sv.length);
  des.getRange(2, 1, sv.length, source.getLastColumn()).setValues(sv);
}

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