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

377
Vistas
How to iterate over a range, get a specific word and paste it to an adjacent column until next key word is found in Google Sheets using scripts?

Impressed with how little I know, after hours trying to figure it out, I have to resort to you.

I'm thinking the process should be the following: Define keywords in an array; Iterate over the range; As the keyword is found, it starts counting until next ketword is found; Counter becomes the number of rows for that category; It starts over again with the next keyword found.

I started writing it, but I can't see multiple for loops here and I wonder how else it'd be:

function formatCells() {
  //Utilities.sleep(3000);

  //Formats Categories and cell colors
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const boqPipeworkSheet = ss.getSheetByName('BOQ Pipework');
  const boqPipeworkRng = boqPipeworkSheet.getRange(5, 1, boqPipeworkSheet.getLastRow(), 14);
  const boqPipeworkValues = boqPipeworkRng.getValues();
  let categoryToPaste = [];
  let categories = ['Copper pipework'];
  let counter = 0;
  for (let r = 0; r < boqPipeworkRng.length; r++) {
    let category = boqPipeworkRng[r][0];
    if (categories.indexOf(category) > -1) {
      categoryToPaste.push(category);
      counter++
    }
  }
}

Here's how the data is: enter image description here

Here is a link to a file containing an example: https://docs.google.com/spreadsheets/d/138TD3eJU6GQtRj3uxXBJicn7pZyeXvAqU8lNcU01BDw/edit?usp=sharing

Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

One solution is to use formula.

For Categories, in F3

={"Category";ArrayFormula(lookup(row(A4:A),row(A4:A)/--REGEXMATCH(B4:B,"^[ ]{2}[A-Z].*"),B4:B))}

For Subcategories, in G3

={"Subcategory";ArrayFormula(if(REGEXMATCH(B4:B,"^[ ]{2}[A-Z].*"),"",lookup(row(A4:A),row(A4:A)/--REGEXMATCH(B4:B,"^[ ]{4}[A-Z].*"),B4:B)))}

enter image description here

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