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

117
Visualizações
Repeat script until conditions are met

I have a google sheet with a timer set for 5am and everyday I want the sheet to:

  1. Refresh, which includes some links to external data, so I add a 10 second pause. There are approximately 100 rows.
  2. I successfully wrote a formula in column U to tell me if data is imported correctly, and if not it returns the text "ERROR".
  3. Search for "ERROR" in column U.
  4. If there are any "ERRORS" in column U, refresh the page again and wait 10 seconds.
  5. Repeat until there are no "ERRORS"
  6. Only when there are no "ERRORS" in column U, copy the values in column V and paste-values in column W.

I think I am close... I just can't figure out how to tell it to re-run the "IF" portion if still finds "ERRORS". Any input is appreciated!

Here is a link to the file -> https://docs.google.com/spreadsheets/d/1GFN3tXRlqxo9J9iNpZMPk-e-WlNGVjJ4zSqZ1_aEE_U

function HardKeyValues() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Players'), true);
  
  SpreadsheetApp.flush();
  Utilities.sleep(10000);
  
  var findVal = spreadsheet.getRange('U:U').getValue()
  if(findVal.match('ERROR')){
  
  SpreadsheetApp.flush();
  Utilities.sleep(10000)}
  
  else{
  spreadsheet.getRange('W:W').activate();
  spreadsheet.getRange('V:V').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);}
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I would not actually use the sleep timer this way

But if I did I would write it like this:

function HardKeyValues() {
  const ss = SpreadsheetApp.getActive();
  const psh = ss.getSheetByName('Players');
  SpreadsheetApp.flush();
  Utilities.sleep(10000);
  const vs = psh.getRange('U1:U' + psh.getLastRow()).getDisplayValues().flat();
  if (vs.find(e => e.includes("ERROR"))) {
    SpreadsheetApp.flush();
    Utilities.sleep(10000);
  } else {
    sh.getRange("V1:V" + sh.getLastRow()).copyTo(sh.getRange("W1:W" + sh.getLastRow(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false));
  }
}

Using indeterminate ranges like "W:W" often leads to many nulls at the end of the array.

about 4 years ago · Juan Pablo Isaza Relatório

0

What about using a while loop ?

function HardKeyValues() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Players'), true);
  
  SpreadsheetApp.flush();
  Utilities.sleep(10000);
  
  var findVal = spreadsheet.getRange('U:U').getValue()
  
  while (findVal.match('ERROR')){
    SpreadsheetApp.flush();
    Utilities.sleep(10000)}
    findVal = spreadsheet.getRange('U:U').getValue()
  }
  
  spreadsheet.getRange('W:W').activate();
  spreadsheet.getRange('V:V').copyTo(spreadsheet.getActiveRange(), 
  SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}

about 4 years ago · Juan Pablo Isaza Relatório

0

You could maybe try using a for loop, just make sure to have a variable that can eventually meet the requirement for the for loop to stop, otherwise, it will turn into a forever loop ;)

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