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

208
Visualizações
How can I separate a column into their own sheet using maps?

I am trying to use this map provided by a previous question I had.

In this case, it takes the sales rep's name, creates a sheet with their name and then moves all orders that belong to them to their sheet. This is what the code looks like.

function sortByRep(sheet){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("All Orders");
  var range = sheet.getRange("A2:H" + sheet.getLastRow());
  var values = range.getValues();
  var sheets = [...new Set(values.map(r => r[6]))].reduce((o, e) => (o[e] = ss.getSheetByName(e) || ss.insertSheet(e), o), {});
  [...values.reduce((m, r) => m.set(r[6], m.has(r[6]) ? [m.get(r[6]), r] : r), new Map())]
    .forEach(([k, v]) => {
      var s = sheets[k];
      if (s) s.getRange(s.getLastRow() + 1, 1, v.length, v[0].length).setValues(v);
    });

But I get this error:

Exception: The parameters (number,number,number,null) don't match the method signature for SpreadsheetApp.Sheet.getRange.

I think it has to be because there are spaces in the names? But I'm not sure.enter image description here

I have added this picture as an example. I want my script to make a new sheet with the sales rep name and move all of their orders to that sheet.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In your script, how about the following modification?

From:

[...values.reduce((m, r) => m.set(r[6], m.has(r[6]) ? [m.get(r[6]), r] : r), new Map())]
  .forEach(([k, v]) => {
    var s = sheets[k];
    if (s) s.getRange(s.getLastRow() + 1, 1, v.length, v[0].length).setValues(v);
  });

To:

[...values.reduce((m, r) => m.set(r[6], m.has(r[6]) ? [...m.get(r[6]), r] : [r]), new Map())]
  .forEach(([k, v]) => {
    var s = sheets[k];
    if (s) s.getRange(s.getLastRow() + 1, 1, v.length, v[0].length).setValues(v);
  });
  • In this modification, both one row and multiple rows can be used.
over 4 years ago · Santiago Trujillo 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