-1

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")
  sheet.getRange("S66:AF66")
  sheet.getRange("S70:AF70")
  sheet.getRange("S72:AF72")
  var me = Session.getEffectiveUser();
  protection.addEditor(me);
  protection.removeEditors(protection.getEditors());
  if (protection.canDomainEdit()) {
    protection.setDomainEdit(false);
  }

}

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.

0

1 Answer 1

0

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().

Related

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

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