Delete a row in google spreadsheet base on contents of cell in row

后端 未结 2 1631
谎友^
谎友^ 2020-12-11 12:12

i have this script to delete certain rows, if the selected cell in the selected colum has the metioned content but i don\'t understand where it fails

    fun         


        
2条回答
  •  一个人的身影
    2020-12-11 13:01

    You need to ensure that the index for deletion is the correct index. When you delete a row all bellow rows has their indexes changed -1. So try this code:

    if (dataCopy1.length > 0) {
    var i = 1;
    
    while (i < DATA_SHEET.getMaxRows() - deleted_rows) {
     if ((dataCopy1[i][FIRST_COLUMN]).search(value_to_check) != -1) {
    
       ss.deleteRow(i - deleted_rows);
      deleted_rows++;
     } 
    i++;
    }
    }
    

提交回复
热议问题