I have like 30 tabs in one google sheet file and all of them have the same structure but different data
I want a script that locks (protect) the whole sheet based on the value
this value is defined as range and I want to lock the tab if the value is (audited)
function protectAudited() {
var ss=SpreadsheetApp.getActive();
var shts=ss.getSheets();
shts.forEach(function(sh) {
if(sh.getRange('A5').getValue()=='audited') {
sh.protect();
}
});
}
Perhaps like this:
function protectAudited() {
var ss=SpreadsheetApp.getActive();
var shts=ss.getSheets();
shts.forEach(function(sh) {
if(sh.getRange('A5').getValue()=='Audited') {
sh.protect();
}else {
var protection=sh.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
if(protection && protection.canEdit()) {
protection.remove();
}
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.