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

202
Vistas
Cross lookup in Google sheets using appscript

Firstly, I'm pretty new to appscript.

I'm trying to extract data based on color cells & map with respective cell data.

https://docs.google.com/spreadsheets/d/12spiCq7bKaqfzTZ4tYrFFAfPyo8l4wZFtyCsZBhns7E/edit#gid=0

My Column A has all the dates. Row 1 with respective names. Range of B2:E has other data with cells highlighted.

I'm able to run appscript to get the coloured cell value in my destination sheet. However, I'm trying for other information the associated highlighted cell

Lets say if the cell B4 with a message, then my output sheet should consist of B4,A4,B1 cells

Here is the script i'm trying out:

function myFunction() {
  const srcSheetName = "Source"; 
  const dstSheetName = "Calendar"; 
  const checkColor = "#ffff00"; 

  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const [src, dst] = [srcSheetName, dstSheetName].map(s => ss.getSheetByName(s));

  const srcRange = src.getDataRange();
  const backgrounds = srcRange.getBackgrounds();

  const values = srcRange.getValues().reduce((ar, r, i) => {
    r.forEach((c, j) => {
      if (backgrounds[i][j] == checkColor) {
        ar.push([c]);
      }
    });
    return ar;
  }, []);
  
  dst.getRange(2, 1, values.length).setValues(values).setBackground("#FFFFFF");
}

Please see if you can help me with this.

Thanks in advance.

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

0

Try

function myFunction() {
  const srcSheetName = "Source";
  const dstSheetName = "Calendar";
  const checkColor = "#ffff00";

  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const [src, dst] = [srcSheetName, dstSheetName].map(s => ss.getSheetByName(s));

  const srcRange = src.getDataRange();
  const backgrounds = srcRange.getBackgrounds();
  const data = srcRange.getValues()

  const result = data.reduce((ar, r, i) => {
    r.forEach((c, j) => {
      if (backgrounds[i][j] == checkColor) {
        ar.push([data[i][0], c, data[0][j]]);
      }
    });
    return ar;
  }, []);

  dst.getRange(2, 1, result.length, result[0].length).setValues(result)
}

input

enter image description here

output

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