Forked from dDondero/find-cell-value-and-delete-row.js
Created
July 25, 2018 18:25
-
-
Save SIFAR786/c4645b3b7bffd947362262b9f478b8b0 to your computer and use it in GitHub Desktop.
Google Apps script function to delete rows based on value in cell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deleteRows() { | |
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] == 'delete' || row[0] == '') { // This searches all cells in columns A (change to row[1] for columns B and so on) and deletes row if cell is empty or has value 'delete'. | |
sheet.deleteRow((parseInt(i)+1) - rowsDeleted); | |
rowsDeleted++; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment