0

I found this amazing masterpiece of @Cooper to search for duplicates based on values in 1 column. Now instead of removing these duplicates as the code does, I want to move them to another sheet. Any idea how this can be done?

Thanks :).

Here is the code:

function removeDuplicates() {
  var sh=SpreadsheetApp.getActiveSheet();
  var dt=sh.getDataRange().getValues();
  var uA=[];
  var d=0;
  for(var i=0;i<dt.length;i++) {
    if(uA.indexOf(dt[i][0])==-1) {
      uA.push(dt[i][0]);
    }else{
      sh.deleteRow(i+1-d++);
    }
  }
}

1 Answer 1

1

Move row

function removeDuplicates() {
  const ss = SpreadsheetApp.getActive();
  const dsh = ss.getSheetByName('Destination');
  var sh=SpreadsheetApp.getActiveSheet();
  var dt=sh.getDataRange().getValues();
  var uA=[];
  let d = 0;
  for(var i=0;i<dt.length;i++) {
    if(uA.indexOf(dt[i][0])==-1) {
      uA.push(dt[i][0]);
    }else{
      dsh.appendRow(dt[i]);//append
      sh.deleteRow(i+1-d++);//delete 
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.