Here is a sample code:
function onEdit(event){
var eventsheet = event.source.getActiveSheet();
var editedcell = event.range;
var rowRange = eventsheet.getRange("A"+editedcell.getRow()+":"+editedcell.getRow());
Logger.log(rowRange.getA1Notation());
var protectcol = 5;
if(editedcell.getColumn() == protectcol){
if(editedcell.getDisplayValue() == 'ON HOLD'){
var protectionrg = rowRange.protect();
protectionrg.addEditor('Email@mail.com'); //Entire Row Protect
protectionrg.removeEditors(protectionrg.getEditors());
Logger.log("PROTECTED");
}
else{
//Remove protection
var protections = eventsheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
protections.forEach(protection => {
var protectedRange = protection.getRange();
if(protectedRange.getRow() == editedcell.getRow()){
//Remove protection
protection.remove();
}
});
}
}
}
Pre-requisite:
Use Installable On-Edit Trigger

Modifications done:
- getRow() returns an integer. If you want to use
protect()
, you need to get either sheet
or range
object. In your case, you want to protect the entire row. Hence you need to get the range
of the entire row. I used Sheet.getRange(a1Notation) to get the range
of the entire row, where a1Notation
is in this format A1:1
(to select row1)
- When the cell in columnE is set to
ON HOLD
, protect the entire row by adding your preferred editor and by removing existing editors using removeEditors(emailAddresses)
Note:
removeEditors()
does not allow the current user to be removed. If the sheet was modified by another user (not Email@mail.com) and set it to ON HOLD
. Your simple onEdit
trigger won't be able to remove this another user as an editor in your protected range. As a workaround, you need to use onEdit
installable trigger, to run the code created by the owner.
Reference: Unable to remove the effective user from editing rights of protected range using script - google sheets
- Lastly, When the cell in columnE is set any value other than
ON HOLD
, get all protected range in the current sheet using getProtections(type), with protection type set to RANGE
. Then loop all existing protection. Check if the protected range's row index is the same with the modified cell's row index. Remove protection using remove()