function Lock(){
var sh = SpreadsheetApp.openById(ssID).getSheetByName('6');
var protection = sh.protect().setDescription('BVDATA');
var me = Session.getEffectiveUser();
protection.addEditor(me).setUnprotectedRanges(sh.getRange("F1:F").createTextFinder("^(?!OK).*$").matchEntireCell(true).useRegularExpression(true).findAll());
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()){
protection.setDomainEdit(false);
}
}
@Tanaike guided me to this. Now i have a problem, that code will automatically protect 1 cell F if it value is OK. Is there a way for me it will protect F:G(like F5:G5 will be protected if F5 value OK) if F has a value of OK?. I tried modification :
protection.addEditor(me).setUnprotectedRanges(sh.getRange("F1:G").CreateTextFinder("^(?!OK).*$").MatchEntireCell(true).useRegularExpression(true).findAll());
but it only protects cell G when the value is OK.