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

118
Visualizações
Duplicate values on column A to column B - Google Apps Script

I'm trying to achieve the following result:

enter image description here

So if column A has duplicate values, I want to show these duplicate values on column B. Here is what I have tried so far. But the code just makes Apple to show two times in a column B. How would I need to alter my code to make it work the way I want?

function findDuplicates() {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = ss.getActiveSheet()
  var lastRow = sheet.getLastRow()
  var data = sheet.getRange(1,1,lastRow).getValues()

  var dataUnique = data.reduce(function (out, item) {
  return out.concat(out.filter(function (comp) {
    return item.toString() != comp.toString();
  }).length ? [] : [item])
  }, []);

  var newValues = sheet.getRange(1,2,dataUnique.length).setValues(dataUnique)
}

This is the result when I run the code:

enter image description here

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

0

This is a spreadsheet created specifically to address this question. It contains the following code that will take values from A and output the result in column B:

function myFunction() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var input = sheet.getRange('A1:A').getValues().filter(e=>e[0]).map(e=>e[0]);
  var inputLower = input.map(e=>e.toLowerCase());

  var output = new Array();
  input.forEach(function (e,i,arr){if(inputLower.indexOf(e.toLowerCase())!=i && output.indexOf(e)==-1){output.push(e)}});
  sheet.getRange(1,2,output.length,1).setValues(output.map(e=>[e]));
}
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