title: How to split single rows into multiple rows depending on whether one cell has values separated by commas or new lines in Google Sheet?
body: <p>The spreadsheet has some cells with cell contents that are separated by commas, or a new line.</p>
  
  <blockquote>
    <p>123, 876, 456</p>
  </blockquote>
  
  <p>Column "C" is the column that determines whether a row should be split up into multiple rows.</p>
  
  <p><a href="https://docs.google.com/spreadsheets/d/1QRuOApb3fxd3b_CXmNlxv0AlXEUuBPqTsfqWrVc0nuQ/edit?usp=sharing" rel="nofollow noreferrer">EXAMPLE Spreadsheet</a></p>
  
  <p>Information from the Form goes into the "Form Submission" page.</p>
  
  <p>We have a specific format that we must meet to submit to our report tracking software that requires the issue numbers (found in Column C) to be separated into their own rows with the information found in Columns A:B, D:J remaining the same (see Desired Outcome sheet). </p>
  
  <p>I found a <a href="https://webapps.stackexchange.com/questions/60861/google-sheets-split-multi-line-cell-into-new-rows-duplicate-surrounding-row-e">similar question</a>  and we implemented it into our Google Sheets.</p>
  
  <p>This script requires, on a separate sheet, the function <code>=result('FormSubmission'!A2:J)</code> to be placed in the first column / row that we wish the data to be displayed (see "Current Outcome" sheet, Cell A2.)</p>
  
  <p>Here is the coding that we are using:</p>
  
  <pre><code>function result(range) {
    var output2 = [];
    for(var i = 0, iLen = range.length; i &lt; iLen; i++) {
      var s = range[i][2].split("\n");    
      for(var j = 0*/, jLen = s.length; j &lt; jLen; j++) {
        var output1 = []; 
        for(var k = 0, kLen = range[0].length; k &lt; kLen; k++) {
          if(k == 2) {
            output1.push(s[j]);
          } else {
            output1.push(range[i][k]);
          }
        }
        output2.push(output1);
      }    
    }
    return output2;
  } 
  
  function results(range) {
    var output2 = [];
    for(var i = 0 /, iLen = range.length; i &lt; iLen; i++) {
      var s = range[i][2].split(",");    
      for(var j = 0 /, jLen = s.length; j &lt; jLen; j++) {
        var output1 = []/; 
        for(var k = 0, kLen = range[0].length; k &lt; kLen; k++) {
          if(k == 2 /) {
            output1.push(s[j]);
          } else {
            output1.push(range[i][k]);
          }
        }
        output2.push(output1);
      }    
    }
    return output2;
  } 
  </code></pre>
  
  <p>If someone submits multiple issue numbers separated by commas in the form, the row needs to be split up into multiple rows, as shown in the Desired Outcome sheet.</p>