2

I would like to know which script to use with the following conditions:

  • Built in trigger Google Sheets at a specific time, not after edit or change.
  • Delete entire rows where the text "canceled" is in one of the cells of column D (4).
  • Should only check in rows >=5.
  • Text "canceled" appears because of a formula in column D.
  • Specific sheets only!

What I have so far, but not working.

function deleterowoncheck (e){
 
    var sheets = ["TEST"]; // Please set your expected sheet names;
    var sheet = e.range.getSheet();
    if (sheets.includes(sheet.getSheetName())) 

   if (e.range.getColumn() == 4 && e.range.getRow() >= 5 && e.range.getValue() == "CANCELED") {

  {

    var sheet = e.range.getSheet(); // Sheet in which the change was made
      sheet.deleteRow(e.range.getRow());
       e.source.toast('Deletion complete.');
  }
}
}
2
  • Since deleterowoncheck is not the name of one of the simple triggers then I assume it must be an installable trigger so which type of trigger did you use? Commented Jan 20, 2023 at 17:26
  • An installable time driven trigger. Commented Jan 21, 2023 at 8:29

1 Answer 1

3

You can try the following script:

function deleteRowOnCheck() {
  var ss = SpreadsheetApp.getActive().getSheetByName("Name of the sheet");
  var data = ss.createTextFinder("CANCELED").findAll();
  for(var i=0; i<data.length; i++)
  {
    var textFinder = ss.createTextFinder("CANCELED");
    textFinder.findNext();
    ss.deleteRow(textFinder.getCurrentMatch().getRow());
  }
}

Just remember to configure the installable time driven trigger as desired.

References:

Sign up to request clarification or add additional context in comments.

5 Comments

Does this search for text in the desired column? Also can I add more sheets?
It searches for text in the whole defined sheet and returns the range where it finds the text, then gets the row and deletes it.
Can you provide me more details on your use case about adding more sheets?
I mean can I use this script for multiple specific sheets only? How to implement this?
You can use the script in other sheets, just create another Apps Script file, then change the name of the sheet in the code and make sure you create another trigger

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.