0

So I'm working on a script to search my Google Sheet for a value and then delete the row, so far I have this:

function sort() { 
  var sheet = SpreadsheetApp.getActiveSheet(); 
  var rows = sheet.getDataRange(); 
  var numRows = rows.getNumRows(); 
  var values = rows.getValues(); 
  var rowsDeleted = 0; 

  for (var i = 0; i <= numRows - 1; i++) { 
    var row = values[i]; 
    if (row[0] == 'test') { 
      sheet.deleteRow((parseInt(i)+1) - rowsDeleted); rowsDeleted++; 
    } 
  } 
}; 

So what I got so far is that I can exact match the text, but I want to find all cols which contains "test" and not only "test". So it will delete rows with data like:

  1. This is a test
  2. Test me again
  3. ThisTestIsNotWorking

Any solution :)?

Klaus
  • 399
  • 1
  • 5
  • 17

1 Answers1

0

Use this instead: if (row[0].indexOf('test') > -1)

The problem with your solution was that it only checked if the row was exactly equal to test, this instead checks if the row contains test at all.

simon
  • 1,095
  • 6
  • 11