Frage

I am working on a spreadsheet that populates from a google form. I figured out how to delete all the data after each week to reset the form and spreadsheet. The problem I am facing is that the form adds new rows with each entry. Eventually the spreadsheet will reach the row limit but I need the form to continue for several years. The code I have thus far is:

herefunction clearRange() {
  var sheet = SpreadsheetApp.getActive().getSheetByName('Form Responses 1');
  sheet.getRange('A8:V100').clearContent();

  for (row>=451; row<1000; row++) {
  sheet.deleteRow(451)
}
}

As it resolves it gives me an error saying: ReferenceError: "row" is not defined. I am new to the programing world and would appreciate any assistance.

War es hilfreich?

Lösung 2

function clearRange() {

        var sheet = SpreadsheetApp.getActive().getSheetByName('Form Responses 1');
        var rows = sheet.getDataRange();
        var numRows = rows.getNumRows();
        sheet.getRange('A8:V100').clearContent();

        for (var row=451; row <= numRows; row++) {
            sheet.deleteRow(row);
        }
    }

Andere Tipps

While the other answer works its slow and will break when there are many rows. Use deleteRows instead to delete them all with a single call. https://developers.google.com/apps-script/reference/spreadsheet/sheet#deleteRows(Integer,Integer)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top