How to prevent adding of new sheets in a Google Sheet

I had created a calculator on Google Sheet

And I was looking for ways to prevent my users from editing certain cells

This I could easily achieve by going to the Data menu and selecting the Protect sheets and ranges option as mentioned below.

Thereafter, Add the cell range to be protected

Next I was wondering how can I look at protecting the user for adding new sheets for which I found this simple app script very useful

Trigger Type Used

 

 

 

How to prevent adding of new sheets in google sheet- Trigger settings
function myFunction() {
  //Testing
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheets = ss.getSheets();
    var sheets_name= "";
      for(i in sheets){
            var sheetName = sheets[i].getName(); 
            if(sheetName . indexOf("Sheet") >  -1 || sheetName.indexOf("Copy of") > -1){
              sheets_name = sheets_name + " "+ sheetName;
              ss.deleteSheet(sheets[i]);
            }
      }
      return sheets_name;
}

 

 

Click on Data and go to Protect Sheets and Ranges

Thereafter, Add the cell range to be protected

Next I was wondering how can I look at protecting the user for adding new sheets for which I found this simple app script very useful

Trigger Type Used

 

 

 

How to prevent adding of new sheets in google sheet- Trigger settings
function myFunction() {
  //Testing
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheets = ss.getSheets();
    var sheets_name= "";
      for(i in sheets){
            var sheetName = sheets[i].getName(); 
            if(sheetName . indexOf("Sheet") >  -1 || sheetName.indexOf("Copy of") > -1){
              sheets_name = sheets_name + " "+ sheetName;
              ss.deleteSheet(sheets[i]);
            }
      }
      return sheets_name;
}

Leave a Reply