1

I am looking to delete rows that have a zero in column E in a particular row range. I have the following script, which will delete the rows with a zero in column E but this seems to apply to the whole spreadsheet.

{
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[4] == 0 || row[4] == '') {
  sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
  rowsDeleted++;
   }
  }

I am looking for help in applying this to a range, such as row 10 through row 20 rather than the entire spreadsheet.

2
  • Sorry, the full script does have the function name at the top. I am not sure I understand you comment, I honestly found some of this script elsewhere and adapted it for my use so I may have some in there that doesn't need to be. Would what you are suggesting allow me to set the deletion to a certain range of rows?
    – jnohl
    Sep 19, 2016 at 21:21
  • A question about a problem should include the minimum necessary information to allow others to reproduce the problem. In the case of script, a function statement is required to be able to run the script, so please include it in script in the question.
    – Rubén
    Sep 19, 2016 at 22:53

1 Answer 1

0

Looks that the OP code was taken from the answer by Mike Grace to Delete a row in Google Spreadsheets if value of cell in said row is 0 or blank

The code doesn't check the entire spreadsheet, just the data range. Anyway to check only the rows from 10 to 20 replace

for (var i = 0; i <= numRows - 1; i++) {

by

for (var i = 9; i <= 20 - 1; i++) {
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.