Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda