title: How can I separate a column into their own sheet using maps?
body: <p>I am trying to use this map provided by a previous question I had.</p>
  <p>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.</p>
  <pre><code>function sortByRep(sheet){
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName(&quot;All Orders&quot;);
    var range = sheet.getRange(&quot;A2:H&quot; + sheet.getLastRow());
    var values = range.getValues();
    var sheets = [...new Set(values.map(r =&gt; r[6]))].reduce((o, e) =&gt; (o[e] = ss.getSheetByName(e) || ss.insertSheet(e), o), {});
    [...values.reduce((m, r) =&gt; m.set(r[6], m.has(r[6]) ? [m.get(r[6]), r] : r), new Map())]
      .forEach(([k, v]) =&gt; {
        var s = sheets[k];
        if (s) s.getRange(s.getLastRow() + 1, 1, v.length, v[0].length).setValues(v);
      });
  </code></pre>
  <p>But I get this error:</p>
  <p>Exception: The parameters (number,number,number,null) don't match the method signature for SpreadsheetApp.Sheet.getRange.</p>
  <p>I think it has to be because there are spaces in the names?  But I'm not sure.<a href="https://i.stack.imgur.com/JxNYf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JxNYf.png" alt="enter image description here" /></a></p>
  <p>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.</p>