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

120
Views
Bucle for en la columna

Tengo problemas con los bucles en una columna. Mi objetivo es iniciar otra función si alguna celda de la columna B tiene un valor.

Aquí mi código que traté de readaptar gracias a las respuestas anteriores.

 let startRow = 2; let lastRow = sheet.getLastRow(); let numRows = lastRow - startRow; let rng = sheet.getRange(2,2).getValues(); for (var i = 0; i < numRows; i++){ let cell = rng[i]; if (cell !== '') { //otherfunction(); } }

El problema es que la otra funcion no arranca

¿Qué estoy haciendo mal?

Gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Explicación:

Problema 1:

  • getRange(2,2) especifica solo una sola celda ( B2 ) pero debido a que usa getValues obtiene una matriz 2D en la forma [[x]] .

Por lo tanto, cuando llamas a rng[i] obtienes algo como [x] que es, de nuevo, una matriz. Por lo tanto, cell !== '' siempre será false .

Problema 2:

Parece que desea iterar sobre la columna B , pero en su código solo considera una sola celda, por lo tanto, el ciclo for no se usa y, de hecho, rng tiene solo una fila (como expliqué antes).

Solución:

 function myFunction() { let ss = SpreadsheetApp.getActive(); let sheet = ss.getSheetByName("Sheet1"); let values = sheet.getRange('B2:B'+sheet.getLastRow()).getValues().flat(); for (var i = 0; i < values.length; i++){ let cell = values[i]; if (cell !== '') { //otherfunction(); } } }
about 4 years ago · Juan Pablo Isaza Report
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!