I need to remove protection for a user that has access to certain cells but needs all the rows and columns when the script is running. After that i then need to protect the sheet again apart from the editable cells.
// Unprotect cells F:AP in addition to any other unprotected ranges in the protected sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var protection = sheet.protect();
var unprotected = protection.getUnprotectedRanges();
unprotected.push(sheet.getRange('F:AP'));
protection.setUnprotectedRanges(unprotected);
// Hides columns
var sheet = ss.getSheets()[1];
var range = sheet.getRange("F:AP");
sheet.hideColumn(range);
The above code works for me, but for someone else it throws an error as they don't have permission to edit.