I'm creating a fun little game in Google Sheets -- the part of code I'm working on now is basically locking the row after a specific cell in that row has been edited (essentially, not letting the user to go back and edit anything before that cell).
My full code is below, but I'm looking for a fix with lines specific to the protections. I want my sheet to add a data range that only allows the email amadle@strengthinsheets.com edit access. However, I'm testing with different accounts, and it seems the protection script is allowing the user to edit (not locking to the specific account).
Is something wrong with this code block? I basically just want to add a protection on the range that doesn't let anyone other than a specific user edit.
function onEdit(e) {
var oldText = "-";
var newText = "=";
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var ss = spreadsheet.getActiveSheet();
// var cell = ss.getRange('AB1').getValue();
var answer = ss.getRange("AA2").getValue();
var syntax = ss.getRange("AC2").getValue();
var description = ss.getRange("AC1").getValue();
var type = ss.getRange("AC3").getValue();
if (ss.getRange("AB1").getValue() == "MATCH") {
SpreadsheetApp.getUi().alert(" Congratulations: "+ answer, "Type: "+type+"\n\nSyntax: "+syntax+"\n\n Description: "+description, SpreadsheetApp.getUi().ButtonSet.OK);
}
if (e.range.getA1Notation() === 'F5') {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("B6:N6").createTextFinder(oldText).matchFormulaText(true).replaceAllWith(newText);
**var ss = SpreadsheetApp.getActive();
var range = ss.getRange('B5:N5'); // Example of protecting Row 1
var protection = range.protect().setDescription('GUESS 1');
var me = "amadle@strengthinsheets.com";
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}**
if (e.range.getA1Notation() === 'F7') {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("B8:N8").createTextFinder(oldText).matchFormulaText(true).replaceAllWith(newText);
}
if (e.range.getA1Notation() === 'F9') {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("B10:N10").createTextFinder(oldText).matchFormulaText(true).replaceAllWith(newText);
var hint = sheet.getRange('AC1').getValue();
SpreadsheetApp.getUi().alert("Function Hint", hint, SpreadsheetApp.getUi().ButtonSet.OK);
}
if (e.range.getA1Notation() === 'F11') {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("B12:N12").createTextFinder(oldText).matchFormulaText(true).replaceAllWith(newText);
}
if (e.range.getA1Notation() === 'F13') {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("B14:N14").createTextFinder(oldText).matchFormulaText(true).replaceAllWith(newText);
SpreadsheetApp.getUi().alert("Next Time! Correct Answer: "+ answer, "Type: "+type+"\n\nSyntax: "+syntax+"\n\n Description: "+description, SpreadsheetApp.getUi().ButtonSet.OK);
}
}