Help With Deleting a Row with a Certain Cell Value

Hi,

I am playing around with scripts with the intent to delete a row on my sheet with a user action (click a toggle making a cell go from False to True). Can anyone assist? Thanks in advance for any help!!

Also, I’m curious if my app trigger is right (or if I need one…).

Here’s what I have so far:
(Found this script on the web and edited it for my sheet.)
function onChange(e) {
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();

//change “main” to the tab sheet name you are using
// getColumn with “Delivered” is currently set to column 4 or D. Change to
//column you are using.

if(s.getName() == “Favorites” && r.getColumn() == 4 && r.getValue() == “TRUE”) {
var row = r.getRow();
s.deleteRow(row);
}
}

You should not name the function “onChange”, let’s call that “DeleteRows”.

The “TRUE” can be perceived the wrong way, I have always used True without the double quotes for conditions.

Otherwise it should be fine and you can go to Edit > Current project’s triggers > Add a trigger for the function, set the event type to On change.

@ThinhDinh, hmmm. Still not sure why it’s not working - but I made the changes you suggested. I’m still fiddling around with it. I figured this would be really simple. These scripts seem to always take me so long to get just right. Let me know if you have any other thoughts… :thinking:

Can you send a duplicate sheet to ariesarsenal@gmail.com so I can test your script with it? Thank you.

1 Like