I created a "form" in google sheets and I protected the sheet except for some editable ranges that require an answer. I need the values from those unprotected cells and copy them in a row to another sheet.
I found a solution from another forum that simply selects all the concerned fields. But I don't want to hardcode the range / cell location because I might add need to edit it in the future.
This is what I have so far:
function cpydata() {
const ss = SpreadsheetApp.getActiveSpreadsheet(); // <<< current spreadsheet
const s1 = ss.getSheetByName("Template");
const s2 = ss.getSheetByName("Summary");
const data = ss.getDataRange().getValues();
const out = [data[1][2], data[2][2], data[3][2], data[4][2], data[5][2], data[6][2]];
s2.getRange(s2.getLastRow()+1, 1, 1, out.length).setValues([out]);
}
function clearUnprotectedRanges() {
var sheet = SpreadsheetApp.getActiveSheet();
var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET);
for (var i = 0; i < protections.length; i++) {
var unProtectedRanges = protections[i].getUnprotectedRanges();
for (var j = 0; j < unProtectedRanges.length; j++) {
unProtectedRanges[j].clearContent();
}
}
Browser.msgBox("Form has been cleared.")
}

The cells in red are unprotected ranges.
Any ideas?


B2:H(last_non-empty_row)from template to summary sheet?function clearUnprotectedRanges() { var sheet = SpreadsheetApp.getActiveSheet(); var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET); for (var i = 0; i < protections.length; i++) { var unProtectedRanges = protections[i].getUnprotectedRanges(); for (var j = 0; j < unProtectedRanges.length; j++) { unProtectedRanges[j].clearContent(); } } Browser.msgBox("Form has been cleared.") }