0

I have a problem deleting rows from my sheet. This code just won't delete rows. Could someone please explain?

function myFunction() {
      var doc = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = doc.getSheetByName("Taulukko1");
      
      var values = sheet.getRange("A1:K28").getValues();
      
      var row_del = new Array();
        
      for(var i=0;i< values.length; i++)
      {
          if(values[i][7] == '17.9.2020'){
          row_del.push(i); 
      }
    }
     
      for (var i = row_del.length - 1; i>=0; i--)   {     
         sheet.deleteRow(row_del[i]);   
   }
    
}
Levsha
  • 63
  • 9
  • Does this answer your question? [Deleting rows in google sheets using Google Apps Script](https://stackoverflow.com/questions/37924842/deleting-rows-in-google-sheets-using-google-apps-script) – Etheraex May 28 '21 at 07:21
  • 1
    I did this according to this topic but my rows are not deleted. – Levsha May 28 '21 at 07:30
  • if I try simply sheet.deleteRow(0); It states that I haven't got any permissions. – Levsha May 28 '21 at 07:39
  • 1
    This is just my guess. In your situation, if the values of the column "H" in your actual Spreadsheet are the date object, I think that `values[i][7] == '17.9.2020'` is always `false`. From `'17.9.2020'` in your script, I'm worry about this. If my understanding is correct, when your script is modified from `var values = sheet.getRange("A1:K28").getValues();` to `var values = sheet.getRange("A1:K28").getDisplayValues();`, what result will you obtain? [Ref](https://developers.google.com/apps-script/reference/spreadsheet/range#getdisplayvalues) – Tanaike May 28 '21 at 07:52
  • I have tried with Date('17.9.2020') with no luck. – Levsha May 31 '21 at 07:08

0 Answers0