2

I'm attempting to remove rows from a sheet based on criteria. I found the following code that works beautifully for what I need:

Delete a row in Google Spreadsheets if value of cell in said row is 0 or blank

However, it isn't clear how the column is being specified. I don't see a e.range.columnStart == 3 like in other answers.

Any guidance on how to read it?

**
 * Deletes rows in the active spreadsheet that contain 0 or
 * a blank valuein column "C". 
 * For more information on using the Spreadsheet API, see
 * https://developers.google.com/apps-script/service_spreadsheet
 */
function readRows() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var values = rows.getValues();

  var rowsDeleted = 0;
  for (var i = 2; i <= numRows - 1; i++) {
    var row = values[i];
    if (row[2] > 1.5 || row[2] < 1) {  
      sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
      rowsDeleted++;
    }
  }
};
Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Your code loops through all rows. It is not triggered on Edit, so there is no event object(e). Columns are referenced by their index. Note that arrays are zero-indexed (so the first column would be row[0]). In your actual code row[2] refers to the column C of the row processed in your loop. – JPV Dec 26 '18 at 16:14
  • Ahh. Thank you! – VladTheCompiler Dec 26 '18 at 19:46

0 Answers0