This question is an exact duplicate of:

I am trying to create a script to protect my formulas in sheets that co-workers will use. I have 10 workbooks with 26 sheets each, all are virtually identical as far as the the locations of the protected and unprotected ranges.

As far as I can tell the best way to do this is to protect the whole sheet then unprotect certain cells for data entry.

This is the script I have so far, I've cut out about 90% of the ranges I need unprotected to make it smaller.

function ProtectRanges() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var protection = sheet.protect().setDescription("Protect Formulas");
  var unprotected = sheet.getRange("S6:AF51")
  var me = Session.getEffectiveUser();
  if (protection.canDomainEdit()) {


The problem I'm having is that the people that I share this with can't edit any of the cells, protected or not. I need to be the only one who can edit the formulas, but the data entry cells need to be open for them to edit.

marked as duplicate by Rubén, serenesat, ale, Alex, jonsca Oct 22 '18 at 23:55

This question was marked as an exact duplicate of an existing question.


The script has a variable named unprotected but that doesn't remove protection. You should use other name for that variable to avoid confusions.

To remove a protection we should use remove().


  • Ok, I don't understand what you are saying. What should that line look like? – keith Oct 11 '18 at 14:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.