Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Copy columns from Sheet1 to Sheet2 & remote duplicates using Google App Script

How can I Copy/append all unique rows from SOURCE Spreadsheet to DESTINATION Spreadsheet.

  • Spreadsheet #1 (SOURCE) - Contains ID's and Names. This sheet has duplicate rows. 500k+ rows (Access: View Only)
  • Spreadsheet #2 (DESTINATION) - Contains only unique ID's with Names. (Access: Edit)

This script works, but it copies all (including duplicates).

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
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use filter with set:

Change SData to

const SData = SRange.getValues().filter(
  (set => row => set.has(row[0]) ? false : set.add(row[0]))(new Set)
);

And modify the destination range:

ds.getRange(1,1,SData.length,SData[0].length).setValues(SData);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!