0

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();}`

3 Answers 3

2

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();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Clear RangeList

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

Comments

0

I believe your goal is as follows.

  • You want to use clearContent() to multiple ranges of 'E7:J12', 'E15:J18' of "OOTW" sheet.

In this case, how about the following sample script?

Sample script:

SpreadsheetApp
  .getActive()
  .getSheetByName('OOTW')
  .getRangeList(['E7:J12', 'E15:J18'])
  .clearContent();

References:

Comments

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.