Hey, I found some code to check if a specified range in your Google Sheet has protections enabled. Here’s a quick breakdown of how it works:
function has_protection(range_string) {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange(range_string);
var range_has_protection = false;
var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
if (protections != "") {
var rngList = protections.map(function(pro) {
return pro.getRange().getA1Notation();
});
var all_ranges_with_protection = sheet.getRangeList(rngList);
var array_of_all_ranges_with_protection = all_ranges_with_protection.getRanges();
for (var r = 0; r < array_of_all_ranges_with_protection.length; r++) {
if (range.getA1Notation() == array_of_all_ranges_with_protection[r].getA1Notation()) {
range_has_protection = true;
}
}
}
return range_has_protection;
}
This function takes a range_string as input (in A1 notation) and checks if the specified range has protection enabled, returning a boolean value.
Has anybody done something similar to this ? is there a way to do this check using formulas ?