简体   繁体   中英

Protect row if cell contains a text

I have a sheet to record some expenses, I shared the sheet with someone but it has a column for my review and I'd like to protect the row if the Columne contains "Approved".

I'd like to protect it using range protect if possible

工作表预览

Protect approved rows

function protectApprovedRows() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('name');
  var sr=2;
  var sc=1;
  var vs=sh.getRange(sr,sc,sh.getLastRow()-sr+1,sh.getLastColumn()-sc+1).getValues();
  var me = Session.getEffectiveUser(); 
  vs.forEach(function(r,i){
    if(r[4]=="Approved") {
      var protection=sh.getRange(i+sr,sc,1,sh.getLastColumn()-sc+1).protect();
      protection.addEditor(me); 
      protection.removeEditors(protection.getEditors()); 
      if (protection.canDomainEdit()) { 
        protection.setDomainEdit(false); 
      }
    }
  });
}

Range.Protect()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM