Exceptions in deleting rows in a spreadsheet

anyway, I would strongly recommend, for anyone who is looking at this topic…** do not use any of these codes if are dealing with the public, high traffic App… only for your personal use, Glide and Google Sheets and Google Scripts work independently, so no matter what, it will be some milliseconds delays, that in-between, some customers can change, related data and create some errors… Just Glide alone is dependent on other services… that is not reliable 100%
The only way you can safely use them is when you create a semaphore code to block unintended changes… always ask pro-coders to help you with that.

I’m not deleting personal data.
My application is for internal use (no response from the university yet). I only deleted 3 sheets: Attendance, file submission, and student assessment. My query only presents the name, id, phone, and lecturer in charge.
To delete the 3 sheets (called reset) only deletes the data in the column outside of the one presented by the query, so that it can be filled with new students in the next term…
So I have the choice of deleting all rows, one by one, or cleaning only the columns, not the personal data (from the query earlier).

did you try my new code yet? if not comfortable trying on an existing App full of data…
create a testing app with dummy data and try it…

No, I didn’t sleep last night. I’ll try it later.

I believe your script is good. Thank you.

1 Like

I’m still having some drinks after the party… so… let me know if I get it right…

Always.

1 Like

Ohh… I forgot to add a little detail for my script… it is for Glide Apps… you need to have a row ID in the first column… just drag it there in GS… top-secret script… don’t share with anybody!
now all the people who read this trend all the way to the and … will be so happy they did that LOL

SA hire us

1 Like

Hi, I found the following script which is quite safe which deletes all data and doesn’t blow up array formulas or queries. But I don’t understand how to trigger with buttons and get dynamic ranges. :v:

function clearDataNotFormulas() {
  
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const ws = ss.getSheetByName("Sheet3");
  const range =ws.getRange("A2:HX");
  const formulas = range.getFormulas();
  //console.log(formulas);
  range.setFormulas(formulas);
}