title: Creating sheets with from master sheet
body: <ol>
  <li>I have a sheet named form responses which gets input from google
  forms,Then I created sheets with names from Column C which is
  employee code and append all the respective rows from form responses
  to the newly created sheets.</li>
  <li>Now I have sheets with name as employee code ( which is in column c of the sheet). Then I want to create secondary sheets from this master sheet(sheets with name as employee code) whose name is using the column E value as attached to the    Employee code.for eg : if Emp code is 10003825 and value in column E is ASR, the sheet name should be 10001515ASR.</li>
  <li>In Column E there are only 4 values ADC,ASR ACC,RSR. let the master sheet(sheets with name as employee code) retain ADC rows always while when other rows containing ASR,ACC,RSR comes append the respective row to the newly created sheet(ie if ASR the row goes to 10001515ASR).</li>
  <li>I have shown my present sheet and expected output</li>
  </ol>
  <p>The code  I developed is shown below:</p>
  <pre><code> function switchSheet(){
      var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
      var sheets = activeSpreadsheet.getSheets();
      for (var i = 1; i &lt; sheets.length; i++) {
         var p =  sheets[i].getSheetName();
         sheetCreateChannel(p);
        }
      }
   function sheetCreateChannel(ss){
     var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
     var sheet1 = activeSpreadsheet.getSheetByName(ss);
     var getNames = sheet1.getDataRange().getValues();
     getNames.shift();
     var sheets = activeSpreadsheet.getSheets();
     var sheetsObj = {};
        for (var i = 0; i &lt; sheets.length; i++) {
         sheetsObj[sheets[i].getSheetName()] = sheets[i];
         for (var i = 0; i &lt; getNames.length; i++) {
           var r = getNames[i];
           if (r[4].toString()== &quot;ASR&quot;&amp;&amp; !((ss+(r[4])) in sheetsObj)) {
                      var newSheet = activeSpreadsheet.insertSheet(ss + &quot;ASR&quot;);
                      sheetsObj[ss+&quot;ASR&quot;] = newSheet;
                     }
           else if (r[4].toString()== &quot;ACC&quot;&amp;&amp;!((ss+(r[4])) in sheetsObj)) {
                var newSheet = activeSpreadsheet.insertSheet(ss + &quot;ACC&quot;);
                sheetsObj[ss+&quot;ACC&quot;] = newSheet;
                     }
           else if (r[4].toString()== &quot;RSR&quot;&amp;&amp; !((ss+(r[4])) in sheetsObj)) {
                var newSheet = activeSpreadsheet.insertSheet(ss + &quot;RSR&quot;);
                sheetsObj[ss+&quot;RSR&quot;] = newSheet;
                }
           else  {
                break;
                }
              }
             } 
           var deleteRows = 0;
             for (var i = 0; i &lt; getNames.length; i++) {
              var r = getNames[i];
               if (r[4].toString() != &quot;&quot;) {
                if ((ss+(r[4])) in sheetsObj) {
                 var Q =ss+(r[4]);
                  sheetsObj[Q].appendRow(r);
               } 
            deleteRows = i + 2;
            }    
           }
          sheet1.getRange(2, 1, deleteRows - 1, sheet1.getLastColumn()).clearContent();
         } 
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ABPfd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ABPfd.jpg" alt="Screen shot of my present sheet" /></a></p>
  <p><a href="https://i.stack.imgur.com/slz7U.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/slz7U.jpg" alt="The expected output" /></a></p>