Skip to main content
added 6 characters in body
Source Link
user0
  • 27.1k
  • 10
  • 53
  • 78

for A column:

function onEdit(event){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0]; // 0 == first sheet.
  var ee = SpreadsheetApp.getActiveSpreadsheet().getActiveRange().getA1Notation();
  if (ee == "A3") { // Check if edited cell is the one we're watching.
    if (SpreadsheetApp.value == "1""true"){ // If the value == "1""true", do stuff.
      var protections = sh.getProtections(SpreadsheetApp.ProtectionType.RANGE);
      for (var i = 0; i < protections.length; i++) {
        if (protections[i].getDescription() == 'Test1') { // If protect. descript. == "Test1"
          protections[i].remove(); // then remove protection.
        }
      }
    } 
  }  
}
  
function setProtected(){
  // Sets the desired range to protected with "Test1" description for demonstration.
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0];
  var protectedRows = sh.getRange("A4:A50");
  protectedRows.protect().setDescription("Test1");
}

for A column:

function onEdit(event){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0]; // 0 == first sheet.
  var ee = SpreadsheetApp.getActiveSpreadsheet().getActiveRange().getA1Notation();
  if (ee == "A3") { // Check if edited cell is the one we're watching.
    if (SpreadsheetApp.value == "1"){ // If the value == "1", do stuff.
      var protections = sh.getProtections(SpreadsheetApp.ProtectionType.RANGE);
      for (var i = 0; i < protections.length; i++) {
        if (protections[i].getDescription() == 'Test1') { // If protect. descript. == "Test1"
          protections[i].remove(); // then remove protection.
        }
      }
    } 
  }  
}
  
function setProtected(){
  // Sets the desired range to protected with "Test1" description for demonstration.
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0];
  var protectedRows = sh.getRange("A4:A50");
  protectedRows.protect().setDescription("Test1");
}

for A column:

function onEdit(event){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0]; // 0 == first sheet.
  var ee = SpreadsheetApp.getActiveSpreadsheet().getActiveRange().getA1Notation();
  if (ee == "A3") { // Check if edited cell is the one we're watching.
    if (SpreadsheetApp.value == "true"){ // If the value == "true", do stuff.
      var protections = sh.getProtections(SpreadsheetApp.ProtectionType.RANGE);
      for (var i = 0; i < protections.length; i++) {
        if (protections[i].getDescription() == 'Test1') { // If protect. descript. == "Test1"
          protections[i].remove(); // then remove protection.
        }
      }
    } 
  }  
}
  
function setProtected(){
  // Sets the desired range to protected with "Test1" description for demonstration.
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0];
  var protectedRows = sh.getRange("A4:A50");
  protectedRows.protect().setDescription("Test1");
}
Source Link
user0
  • 27.1k
  • 10
  • 53
  • 78

for A column:

function onEdit(event){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0]; // 0 == first sheet.
  var ee = SpreadsheetApp.getActiveSpreadsheet().getActiveRange().getA1Notation();
  if (ee == "A3") { // Check if edited cell is the one we're watching.
    if (SpreadsheetApp.value == "1"){ // If the value == "1", do stuff.
      var protections = sh.getProtections(SpreadsheetApp.ProtectionType.RANGE);
      for (var i = 0; i < protections.length; i++) {
        if (protections[i].getDescription() == 'Test1') { // If protect. descript. == "Test1"
          protections[i].remove(); // then remove protection.
        }
      }
    } 
  }  
}
  
function setProtected(){
  // Sets the desired range to protected with "Test1" description for demonstration.
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheets()[0];
  var protectedRows = sh.getRange("A4:A50");
  protectedRows.protect().setDescription("Test1");
}