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

176
Visualizações
I'm looking to move cells with color highlighted to different sheet

I'm looking to copy the cells highlighted in particular color to the different sheet in one column.

Sample doc: https://docs.google.com/spreadsheets/d/1Xa_WKlmHO5mT688zM0O-LXlqnSbITG2YK1uLPq5XzcA/edit#gid=328987545

Can you help me with the script to get desired output?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I believe your goal is as follows.

  • You want to retrieve the values of the highlighted cells (From your provided Spreadsheet, it's #ffff00), and want to put the values to the column "A" of destination sheet.
  • You want to achieve this using Google Apps Script.

In this case, how about the following sample script?

Sample script:

function myFunction() {
  const srcSheetName = "Sheet1"; // This is from your sample Spreadsheet.
  const dstSheetName = "Ouput"; // This is from your sample Spreadsheet.
  const checkColor = "#ffff00"; // This is from your sample Spreadsheet.

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

  // Retrieve source values and backgrounds.
  const srcRange = src.getDataRange();
  const backgrounds = srcRange.getBackgrounds();

  // Create an array for putting to the destination sheet.
  const values = srcRange.getValues().reduce((ar, r, i) => {
    r.forEach((c, j) => {
      if (backgrounds[i][j] == checkColor) {
        ar.push([c]);
      }
    });
    return ar;
  }, []);
  
  // Put the array to the column "A" of the destination sheet.
  dst.getRange(1, 1, values.length).setValues(values).setBackground(checkColor);
}
  • When this script is run, the values are retrieved from the highlighted cells of the source sheet. And, the retrieved values are put to the column "A" of the destination sheet.
  • From your sample Spreadsheet, the destination sheet has the highlighted cells. So, I added setBackground(checkColor). If you don't want to set the color, please remove it.

References:

  • getBackgrounds()
  • getValue()
  • setValues(values)
  • reduce()
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