Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda