Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda