Is there a way to transfer only unique rows from a SOURCE Spreadsheet to a DESTINATION spreadsheet?
- Spreadsheet #1 (SOURCE) - This sheet contains ID's and Names, but has duplicate rows. There are over 500k rows in this sheet and it is view-only.
- Spreadsheet #2 (DESTINATION) - Here, we want to have only unique ID's with their corresponding Names. You can edit this sheet.
The current script successfully copies the data, but unfortunately, it includes duplicates as well.
function transferIDs() {
var sss = SpreadsheetApp.openById('%'); //SOURCE
var ss = sss.getSheetByName('Sheet1');
var SRange = ss.getDataRange();
var A1Range = SRange.getA1Notation();
var SData = SRange.getValues();
var dss = SpreadsheetApp.openById('#'); //DESTINATION
var ds = dss.getSheetByName('Sheet1');
ds.clear({contentsOnly: true});
ds.getRange(A1Range).setValues(SData);
}
Spreadsheet #1 SOURCE (contains duplicate rows)
A | B |
---|---|
ID | Name |
X123456 | John |
Y112233 | Sarah |
X998877 | Amanda |
012344 | Bob |
X998877 | Amanda |
Spreadsheet #2 DESTINATION (Populated using GAS, no duplicates, Expected Outcome)
A | B |
---|---|
ID | Name |
X123456 | John |
Y112233 | Sarah |
X998877 | Amanda |
012344 | Bob |