JavaScript - Button - yes/no. No should not clear cells

9 Views Asked by At

I am using Google Sheets apps script. I want to leave the cells alone if "no" is clicked.

I have a pop up when the sheet opens and if "no" is clicked then the script still clears the cells. I only want the cells to clear when "yes" is clicked and leave the data in the cells if "no" is clicked. What am I missing?

function ClearCells() {
  var sheet = SpreadsheetApp.getActive().getSheetByName('Worksheet');
  sheet.getRange('B1:B7').clearContent();
  sheet.getRange('B9').clearContent();
  sheet.getRange('E3:E8').clearContent();
  sheet.getRange('H3:H8').clearContent();
  }

  function onOpen() {
  var ui = SpreadsheetApp.getUi();

  var buttonPressed = ui.alert('Do you want to clear data on the worksheet?', ui.ButtonSet.YES_NO);

 if(buttonPressed == ui.Button.YES);
  ClearCells();
  }
0

There are 0 best solutions below