0

I have a spreadsheet with a time-driven trigger that clears a range every week.

This is my current script.


function clearWeekly() {
  //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('OnGoing');
  sheet.getRange('F3:F').clearContent();

}

I want to update my script so that it clears Column F only where the cell value in Column B = SMM. Column F consists of checkboxes.

Can someone help here?

You can view my spreadsheet here: https://docs.google.com/spreadsheets/d/1r7yjUMdK4eDY328Zeg41pYHTmjHa5slzBLEnVP2GzI8/edit?usp=sharing

2
  • 1
    Please make your question more specific by briefly describing your search/research efforts to update your script. Commented May 6, 2020 at 13:35
  • Hi. I'm guessing that you are in the dark about what to do. In brief, you need to loop through each row, test whether column B = "SMM", and then clear the contents of Column F. [How do I loop through rows to check a value in Google Apps Script](56459074) is a pretty good example that you can adapt to your scenario. If you have a lot of data, then it is not efficient to update the column F value inside the loop, but you can ask about that in another question if it becomes an issue.
    – Tedinoz
    Commented May 9, 2020 at 7:17

1 Answer 1

1

I was able to make it work using the code below. I used this answer as a reference: Google sheets loop search for string and clear adjacent cells

function deleteRows() {
    var sheet = SpreadsheetApp.getActive().getSheetByName('OnGoing');
  var lr=sheet.getLastRow()
  var lc=sheet.getLastColumn()
  var a = sheet.getRange(3, 1, lr, lc).getValues();
  for (var i = 0; i < a.length-1; i++) {
          if (a[i][1].indexOf("SMM")!= -1){
           var delete1=sheet.getRange(i+3, 6, 1, 23)
           var delete2=sheet.getRange(i+3, 29, 1, 6)
           delete1.clearContent()
           delete2.clearContent()
   }}}

Your Answer

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

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