I was working on some automation and wanted to remove the duplicate rows in my google sheet by comparing it on basis of 3rd column. I found one code which is working flawlessly but it does not remove the old entry in sheet, it removes the latest one. I wanted to keep the latest one from the duplicates.
This is the code which I found for appscript by
After:
Update
If there will some glitches it makes sense to add the command flush()
after every deleteRow()
. The last line of the code should be like this:
// remove rows by the indexes
duplicates.reverse().forEach(x => { sh.deleteRow(x); SpreadsheetApp.flush() });