Home > Net >  Can I clear two seperate ranges with a button script? Google Sheets
Can I clear two seperate ranges with a button script? Google Sheets

Time:10-11

I'm trying to clear two seperate ranges with the click of a button but can't figure out how to combine the ranges together

I use this for one range and the other range I need to combine is 'E15:J18'

function ClearCells() {

var sheet = SpreadsheetApp.getActive().getSheetByName('OOTW');

sheet.getRange('E7:J12').clearContent();}`

CodePudding user response:

If I understand you correctly, you want to clear multiple, discontinuous ranges on a Spreadsheet with a single function.

My suggestion would be to add another line to your function that gets the subsequent discontinuous range, and clears it.

function clearCells() {
  const sheet = SpreadsheetApp.getActive().getSheetByName("OOTW");
  sheet.getRange("E7:J12").clearContent();
  sheet.getRange("E15:J18").clearContent();
}

CodePudding user response:

Clear RangeList

function clearRangeList() {
  SpreadsheetApp.getActiveSheet().getRangeList(["E7:J12","E15:J18"]).getRanges().forEach(rg => rg.clearContent())
}
  • Related