Skip to main content
fixed code indent for readability
Source Link
ale
  • 52.9k
  • 42
  • 165
  • 314
 function onEdit(e) {
                var range = e.range;  //gets cell to edit
                 var companyName = range.getValue();  //gets value of cell
                 var column = range.getColumn();  //gets the column number of the cell
              var thisSheetNumber = range.getSheet().getIndex();

            //make sure this is the correct column on the correct sheet
             if (column == 5 && thisSheetNumber == 1)                       
              {
                     //searches for a sheet that matches the companyName
                   var sheetNotFound = true;    
                   var sheets = SpreadsheetApp.getActive().getSheets();

                  for (var i = 0; i<sheets.length; i++)                     
                     {
                      //if it finds matching sheet stops
                      if (sheets[i].getName() == companyName)                                 
                        {
                         sheetNotFound = false;
                            break;
                        }
                     }
                //else creates the sheet
               if (sheetNotFound)  
                  {
                    SpreadsheetApp.getActive().insertSheet(companyName);
                  }
             }
 }
 function onEdit(e) {
                var range = e.range;  //gets cell to edit
                 var companyName = range.getValue();  //gets value of cell
                 var column = range.getColumn();  //gets the column number of the cell
              var thisSheetNumber = range.getSheet().getIndex();

            //make sure this is the correct column on the correct sheet
             if (column == 5 && thisSheetNumber == 1)                       
              {
                     //searches for a sheet that matches the companyName
                   var sheetNotFound = true;    
                   var sheets = SpreadsheetApp.getActive().getSheets();

                  for (var i = 0; i<sheets.length; i++)                     
                     {
                      //if it finds matching sheet stops
                      if (sheets[i].getName() == companyName)                                 
                        {
                         sheetNotFound = false;
                            break;
                        }
                     }
                //else creates the sheet
               if (sheetNotFound)  
                  {
                    SpreadsheetApp.getActive().insertSheet(companyName);
                  }
             }
 }
function onEdit(e) {
  var range = e.range;  //gets cell to edit
  var companyName = range.getValue();  //gets value of cell
  var column = range.getColumn();  //gets the column number of the cell
  var thisSheetNumber = range.getSheet().getIndex();

  //make sure this is the correct column on the correct sheet
  if (column == 5 && thisSheetNumber == 1)                       
  {
    //searches for a sheet that matches the companyName
    var sheetNotFound = true;    
    var sheets = SpreadsheetApp.getActive().getSheets();

    for (var i = 0; i<sheets.length; i++)                     
    {
      //if it finds matching sheet stops
      if (sheets[i].getName() == companyName)                                 
      {
        sheetNotFound = false;
        break;
      }
    }
    //else creates the sheet
    if (sheetNotFound)  
    {
      SpreadsheetApp.getActive().insertSheet(companyName);
    }
  }
}
Source Link

I hope this will work Correctly

 function onEdit(e) {
                var range = e.range;  //gets cell to edit
                 var companyName = range.getValue();  //gets value of cell
                 var column = range.getColumn();  //gets the column number of the cell
              var thisSheetNumber = range.getSheet().getIndex();

            //make sure this is the correct column on the correct sheet
             if (column == 5 && thisSheetNumber == 1)                       
              {
                     //searches for a sheet that matches the companyName
                   var sheetNotFound = true;    
                   var sheets = SpreadsheetApp.getActive().getSheets();

                  for (var i = 0; i<sheets.length; i++)                     
                     {
                      //if it finds matching sheet stops
                      if (sheets[i].getName() == companyName)                                 
                        {
                         sheetNotFound = false;
                            break;
                        }
                     }
                //else creates the sheet
               if (sheetNotFound)  
                  {
                    SpreadsheetApp.getActive().insertSheet(companyName);
                  }
             }
 }