Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9787

Remove All Protections on Selected Range

$
0
0

I am trying to remove all protections on a range. I created a script that adds a protection when a user pushes a button. If the user pushes the button twice, it adds the protection twice. I came up with this script, mostly through recording macros, to remove the protection, but it only removes one protection. If a user pushes the button twice, this button only removes one protection and leaves the other protection (thus, leaving the range protected when it shouldn't be). Any advice on how I can remove ALL protections on the range?

var allProtections = spreadsheet.getActiveSheet().getProtections(SpreadsheetApp.ProtectionType.RANGE);  var matchingProtections = allProtections.filter(function(existingProtection) {  return existingProtection.getRange().getA1Notation() == 'C4:F30';  });  var protection = matchingProtections[0];  protections.remove();

Viewing all articles
Browse latest Browse all 9787

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>