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

151
Visualizações
Google Script Explanation

I have a Google App Script that is supposed to read each row, see if Column C is marked "true", and if true data validation needs to be removed from all columns in that row. The example code below is not working. I am hoping someone can help educate me as to why.

function skl(){
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet2 = ss.getSheetByName('Savings Register');
    var columnO2 = sheet2.getRange(2, 1, sheet2.getLastRow()-1, 1);
    var oValues2 = columnO2.getValues();
    for (var i = 0; i < oValues2.length; i++) {
        if (oValues2[i][2] == 'TRUE') {
            sheet2.getRange(i + 2, 1, 1, 9).setDataValidation(null);
        }
    }
}

If I change it to if (oValues2[i][0] == 'TRUE') the code functions when column A is true... but my criteria is column C. Shouldn't this code work with column C being the number 2?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

var columnO2 = sheet2.getRange(2, 1, sheet2.getLastRow()-1, 1);

Your range is essentially specifying "A2:A", therefore column C is not included.

Here's a solution:

function myFunction() {

  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Savings Register');
  const data = sheet.getSheetValues(2, 1, sheet.getLastRow()-1, sheet.getLastColumn());

  const targetRows = data.filter(i => i[2] === true);

  for (let row of targetRows) {
    const index = data.findIndex(i => i === row)+2;
    sheet.getRange(index, 1, 1, 9).setDataValidation(null);
  }

}

If you have any issues please let me know!

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