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

Script Failing to Finish - Protected Sheet

$
0
0

I've been using a timed trigger with this script to add new columns daily to a school-wide tracking sheet. Recently, I've been getting notifications that the script is failing on only one of the sheets -- the second sheet in.

This is the error message I'm getting: "Exception: You are trying to edit a protected cell or object. Please contact the spreadsheet owner to remove protection if you need to edit."

I'm confused because the sheet that is failing isn't the one that is protected. The first sheet I have is protected (always has been and it's worked fine), but I have the code set to only run on the 2nd sheet onwards (see code below). It's the 2nd sheet that is failing to add the new columns. All other sheets work fine. There is nothing protected on the 2nd sheet.

This issue only started happening recently. It worked fine for over a year. Hoping someone can take a look and see where I'm going wrong. Can add more context if needed!

var ss = SpreadsheetApp.getActiveSpreadsheet();var sheets = ss.getSheets();function doToEachSheet() {  for (let i = 2; i < sheets.length; i++) {    let x = ss.setActiveSheet(sheets[i]);//  +-----------------+//  | loop through -> |//  +-----------------+    x.insertColumnsBefore(4, 2);    x.getRange('D2').setValue('=F2+1');    let nDate = x.getRange('D2').getValue();    let values = [ [ nDate, null ],[ "Left", "Returned" ] ];    x.getRange('D2:E3').setValues(values);    let rng = x.getRange('D2:E184');    rng.setBorder(true, true, true, true, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID_THICK );    rng.setBorder(null, null, null, null, null, true, '#818181', null );    rng.setBorder(null, null, null, null, true, null, '#d8d4d4', null );      for ( let j = 3; j < 184; j+=5 ) {      let r = "D" + [j] +":E" + [j];      x.getRange(r).setBorder( null, null, true, null, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID_THICK );    };//  +----------+//  | end loop |//  +----------+  }}

Viewing all articles
Browse latest Browse all 9786

Trending Articles



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