The following piece of code makes it is possible to create different protected ranges throughout a spreadsheet at once.
Code
var app = SpreadsheetApp.getUi();
var ss = SpreadsheetApp.getActive();
function onOpen() {
app.createMenu("Ranges")
.addItem("Set ranges", "setRanges")
.addItem("Delete ranges", "deleteRanges")
.addToUi();
}
function setRanges() {
var text = app.prompt("Give string", "Like A1:A10, Sheet2!A4:B5, This is a test!A:A", app.ButtonSet.OK_CANCEL);
if(text.getSelectedButton() == app.Button.OK) {
var ranges = text.getResponseText().split(",");
for(var i = 0, iLen = ranges.length; i < iLen; i++) {
var value, range, index, sname, split, sh;
value = ranges[i].trim(), split = value.split("!");
switch(split.length) {
case 1:
range = value;
sh = ss.getActiveSheet();
break;
case 2:
range = value;
sh = ss.getSheetByName(String(split[0].trim()));
break;
default:
index = value.lastIndexOf("!");
range = "'" + value.slice(0, index) + "'!" + split[split.length - 1].trim();
sh = ss.getSheetByName(String(value.slice(0, index)));
break;
}
try {
sh.getRange(String(range))
.protect()
.setDescription("Range" + i);
} catch(e) {
throw "Range: " + (i) + " doesn't exist";
}
}
}
}
function deleteRanges() {
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var j = 0, jLen = protections.length; j < jLen; j++) {
protections[j].remove();
}
}
Explained
The first two variables are usable throughout the code. The onOpen() function creates a menu item upon file opening and adds two items. The setRanges() function initially creates a popup box (prompt
) to capture the string. The response is then split using the comma as delimiter.
Now we need to iterate though the different ranges in order to prepare the protected ranges. Within the iteration, the response is validated once more by splitting it using the exclamation mark as delimiter. This will yield either one or more results. The switch method will determine the buildup of the sheet name and the range.
Now that the sheet has been defined, the range (getRange()
) can be protected (protect()
) and the try / catch
allows for some error handling.
Screenshot

Note
This script can also cope with the following sheet name examples:
Example
I've created an example file for you: setting up multiple protected ranges
Add this script in the script editor (Tools > Script editor) and press the bug button:

Now you can use the script.