2

I have this code from another question that works perfectly for me, but I'd like to get it to remove the duplicates of every sheet and not just the currently active one. This is also for large spreadsheets with a lot of data, so I have to keep the 6min execution time maximum in mind as well. Does anyone have any ideas?

Here's my code:

function removeDuplicates() {
  SpreadsheetApp.getActiveSheet().getDataRange().removeDuplicates();
}

1 Answer 1

2

How about the following modification?

From:

SpreadsheetApp.getActiveSheet().getDataRange().removeDuplicates();

To:

SpreadsheetApp.getActiveSpreadsheet().getSheets().forEach(sheet => sheet.getDataRange().removeDuplicates());
  • In this modification, all sheets are retrieved with getSheets() and the duplicated rows of each sheet is removed with removeDuplicates() in a loop.

References:

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect. Thank you very much!
@Michael Hawk Thank you for replying and testing it. I'm glad your issue was resolved. Thank you, too.

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.