I have an app script attached to my Google Spreadsheet. There is a function that does a bunch of stuff withing the spreadsheet. Here is what it does.
- Create a new Sheet
- Set column header for new sheet
- Copy data in new sheet
- Set Formulas
- Delete Extra columns
- Delete Extra rows
- Add A row in an existing sheet(Sheet 1)
- Add a column in an existing sheet(Sheet 2)
- Add Formula in new column in Sheet 2
- Edit Value in an existing sheet's cell (Sheet 3).
After these 10 steps are complete, the spreadsheet works normally but after 10-15 secs, the sheet will freeze. To get it to work, I need to refresh the page.
I experimented and I found out that if I eliminate Step 6 i.e "Delete Extra rows", the freeze behavior is eliminated. Why does it freeze on this particular step? How do I fix this? I cannot not delete extra rows. Here is the exact piece of code where it freezes.
var unwanted = newAssignmentSheet.getMaxRows() - (parseInt(i) + 6);
newAssignmentSheet.deleteRows(i+7, unwanted); //FREEZES HERE
Point to note :
If I implement Step 6 in isolation, the Spreadsheet does not freeze.