Reputation: 1
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();}`
Upvotes: 0
Views: 672
Reputation: 201398
I believe your goal is as follows.
clearContent()
to multiple ranges of 'E7:J12', 'E15:J18'
of "OOTW" sheet.In this case, how about the following sample script?
SpreadsheetApp
.getActive()
.getSheetByName('OOTW')
.getRangeList(['E7:J12', 'E15:J18'])
.clearContent();
Upvotes: 0
Reputation: 64072
function clearRangeList() {
SpreadsheetApp.getActiveSheet().getRangeList(["E7:J12","E15:J18"]).getRanges().forEach(rg => rg.clearContent())
}
Upvotes: 0
Reputation: 43
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();
}
Upvotes: 2