0

I am trying to automate copying data from 'source' tab to 'target tab'. The source tab will have data constantly refreshed from sql add-in and wish to only add new unique data to the bottom of target tab (based on id in column A) while ignoring duplicate data. Would like to have script run in early morning hour but haven't figured out that part yet.

Thank you for your time and efforts.

function keepUnique(){
  var col = 0 ; // choose the column you want to use as data source (0 indexed, it works at array level)

  var ss = SpreadsheetApp.getActiveSpreadsheet()

  var ms = ss.getSheetByName("source");
  var sh = ss.getSheetByName("target");

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var data=ms.getDataRange().getValues();// get all data
  Logger.log(data);
  var newdata = new Array();
  for(nn in data){
    var duplicate = false;
    for(j in newdata){
      if(data[nn][col] == newdata[j][0]){
        duplicate = true;
      }
    }
    if(!duplicate){
      newdata.push([data[nn][col]]);
    }
  }
  Logger.log(newdata);
 sh.getRange(3,1,newdata.length,newdata[0].length).setValues(newdata);// paste new values sorted in column of your choice (here column 8, indexed from 1, we are on a sheet))
  }

0 Answers0