I am trying to remove the protection from a specific cell after its content is deleted and then change it'sits background to white.
Thank you in advance.
Here is the script:
function onEdit(e) {
var spreadsheet = SpreadsheetApp.getActive();
const range = e.range;
var cell = SpreadsheetApp.getActiveSheet().getActiveCell();
var a1o = cell.getA1Notation();
a1 = "'" +a1o+ "'"
var val = cell.getValue();
if (val == "") {
var allProtections =
spreadsheet.getActiveSheet().getProtections(SpreadsheetApp.ProtectionType.RANGE);
var matchingProtections = allProtections.filter(function(existingProtection) {
return existingProtection.getRange().getA1Notation() == +a1;
});
var protection = matchingProtections[0];
protection.remove();
ss.getActiveRangeList().setBackground('White');
}
}