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

164
Views
Google Apps Script: inserte valores en la columna B en función de los valores de la columna A, cuando hay miles de filas

Tengo un guión que necesito mejorar. El script recorre todas las filas de la columna A. Luego, inserta un valor en la siguiente celda según el valor. Por ejemplo: si el valor en la celda A2 es 4,9, entonces insertará UNDER10 en la celda B2. Funciona. Pero, funciona tan lentamente. Si tengo miles de filas en la columna A, a veces el script se agota. ¿Alguien sabe una manera de hacer este script más rápido?

ingrese la descripción de la imagen aquí

A continuación se muestra mi guión:

 function myFunction() { const ss = SpreadsheetApp.getActive().getActiveSheet() const lastRow = ss.getLastRow(); for (var i = 1; i < lastRow +1; i++) { var value = ss.getRange(i,1).getValue(); var newValue = ss.getRange(i,2); if (value < 10) { newValue.setValue("UNDER10"); } else if (value < 20) { newValue.setValue("UNDER20"); } else if (value > 20) { newValue.setValue("OVER20"); } } }

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

0

Esta mejora debería funcionar. Tenga en cuenta que asumí que la columna A incluye números (la hoja de Google se refiere a 4,9 como cadena. Por lo tanto, la declaración if(value < 10) no es realmente válida).

Para probar mi código, usé 4.9, 14.9, etc.

 function myFunction() { const ss = SpreadsheetApp.getActive().getActiveSheet() const lastRow = ss.getLastRow(); // get all the range at once let range = ss.getRange(2, 1, lastRow -1, 2); // get all the values in 2D array let values = range.getValues(); // for each pair of values [price, custom value], calculate the custom value values.forEach((value)=> { // NOTE that i parse float out of price. // Google sheet refer 4,9 as string (i assume you ment 4.9) value[0] = parseFloat(value[0]) if (value[0] < 10) { value[1] = "UNDER10" } else if (value[0] < 20) { value[1] = "UNDER20"; } else if (value[0] > 20) { value[1] = "OVER20"; } }) // set the new values into the spreadsheet range.setValues(values) }

Si desea comparar cada número en cada fila (por ejemplo, en la celda 'A2': if(4 < 10 && 9 < 10) ), comente y lo corregiré en consecuencia.

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!