0
votes

Currently, I have 2 tabs in a spreadsheet that have nearly identical data.

The 1st tab is imported from another spreadsheet and has employee names and their team. My second tab has the same information, but it is manually updated.

The 2nd tab has columns to the right that depend on the employee names being in those specific cells, making it difficult to do a direct IMPORTRANGE to this sheet because if something was edited in the middle, the columns on the right would all be incorrect and no longer match to the correct employee.

I am curious if there is a way in Google Apps Script if I could set up a time event trigger that compares the two tabs, finds the difference in employee names, and adds the missing names to the bottom of the first tab. I'm sorry for the lack of code, I have no idea where this would start and how to compare two data sets for difference in Apps Script.

Links to sample sheets:

Imported Data - https://docs.google.com/spreadsheets/d/1NjIReOZhSmF_eaSBrt6nmUh__ycPDgPvmJ-K-APMU0I/edit?usp=sharing

Working Sheet - https://docs.google.com/spreadsheets/d/1bFdVw0uzP7TX7JXsZ1iYajk85bKfHRrBPR02ZFDtRAU/edit?usp=sharing

1
Your first link is not public.Cooper
Sorry, forgot I made that sheet with my work email. It is now updated with access.Bryce Sinclair

1 Answers

0
votes

This returns an array with the names that are not in both lists or it return a null Array.

function findNewNames() {
  var ss=SpreadsheetApp.getActive();
  var sh1=ss.getSheetByName('Sheet1');
  var sh2=ss.getSheetByName('Sheet2');
  var nl1=sh1.getRange(1, 1,sh1.getLastRow(),1).getValues().map(function(r){return r[0]});
  var nl2=sh2.getRange(1, 1,sh2.getLastRow(),1).getValues().map(function(r){return r[0]});
  var d=0;
  if(nl1.length>nl2.length) {
    var lA=nl1.slice();
    var sA=nl2.slice();
  }
  if(nl2.length>nl1.length){
    var lA=nl2.slice();
    var sA=nl1.slice();
  }
  if(nl1.length==nl2.length) {
    return [];
  }
  for(var i=0;i<lA.length;i++) {
    if(sA.indexOf(lA[i-d])>-1) {
      lA.splice(i-d++,1)
    }
  }
  return lA;
}