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

176
Views
Google Script -- Copy data from spreadsheet 1 to spreadsheet 2, update sheet 2 only if change to sheet 1

I have two spreadsheets. The main file gets pulled from one system and is updated once per week. Spreadsheet 2 is a mirror of this sheet -- that allows more users to edit / make pivot tables. Previously the IMPORTRANGE function was being used -- however this seems to not be pulling in all of the data, so I pieced together a script that seems to get all of the data. However, I'm running into a few issues.

function myFunction() {
var sss = SpreadsheetApp.openById('1234'); //source sheet ID
var ss = sss.getSheetByName('Data'); //source worksheet name
var range = ss.getRange('1:5710');      //assign the range you want to copy
var rawData = range.getValues()     // get value from source sheet
var data = []                       // filtered data will be stored in this array
for (var i = 0; i< rawData.length ; i++){
if(rawData[i][10] == "Michael Scott")            // check to see if column K says 'Michael Scott' if not skip it
{
data.push(rawData[i])
}
}

var tss = SpreadsheetApp.openById('456'); //destination sheet ID
var ts = tss.getSheetByName('destination'); //destination worksheet name
var tsss = ts.getRange('A2:AT').clearContent() // clears all content in the sheet except the header
ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);

}

I've put this together and it appears to work. One thing I can't seem to figure out is how the function for pulling data if it exists in column K works. K is 11...but the formula shows 10 (I got lucky and someone else asked a question like this and their sheet also used column K, so I copied this and it works but I don't understand how).

The other problem seems to be that -- anytime an update is made in either sheet -- it will revert those changes in the main sheet, and update the 2nd sheet. What I would like this to do is simply work so that if there is a change in the main sheet -- it will update in the destination sheet (but will preserve the 1st row, frozen columns in the destination sheet).

about 4 years ago · Juan Pablo Isaza
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!