1
votes

I have a spreadsheet that is protected except for certain cells/ranges (for example sheet is protected except for range B2:D6 and B10:D15). I also have an insert row function that employs a WebApp to override the protection when the user wishes to insert rows within the allowable ranges. Unfortunately this allows the user to insert rows anywhere in the sheet as it overrides all protection for the duration of the script exedcution.

I need to check first to see if the current cursor position (active cell) is within the allowable range. If so continue, if not abort with appropriate message.

Protection has been set up using Data > Protected sheets and ranges > Sheet > Except certain cells. Permissions set to 'Only you'.

1

1 Answers

1
votes

You may check if user can edit the range:

  var file = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = file.getSheetByName('Sheet1');
  var range = sheet.getRange("A1:B10");
  // whether the user has permission to edit
  // every cell in the range
  Logger.log(range.canEdit());