脚本不清除单元格

Script not Clearing cells

很抱歉问这个问题,我读了那么多书。该脚本确实完成了,但它没有清除选定的单元格。我做错了什么?请帮忙?

   // Display a dialog box with a message and "Yes" and "No" buttons.
    var ui = SpreadsheetApp.getUi( );
    var response = ui.alert('Are you sure you want to continue?', ui.ButtonSet.YES_NO);

   // Process the user's response.
   if (response == ui.Button.YES) {
   Logger.log('The user clicked "Yes."');
   } else {
   Logger.log('The user clicked "No" or the dialog\'s close button.');
   }  
   function clearRange() {
  //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('LOAD ASSIGNMENT');
  sheet.getRange('A4:L120').clearContent();
   }

Warning: unused function clearRange.
叫它:)
定义函数后,您缺少:
clearRange();

正如其他人所逃避的那样,您已经使函数 clearRange 变得清晰,但是您 activate/call 在哪里做不到。我想我会包含更改后的代码,以便您了解调用该函数的含义。

    function myFunction() {

    function clearRange() {
  //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('LOAD ASSIGNMENT');
  sheet.getRange('A4:L120').clearContent();
   }


   // Display a dialog box with a message and "Yes" and "No" buttons.
    var ui = SpreadsheetApp.getUi( );
    var response = ui.alert('Are you sure you want to continue?', ui.ButtonSet.YES_NO);

   // Process the user's response.
   if (response == ui.Button.YES) {

     // Just to clarify, you have created the clearRange function. I've moved it above. But no where do you say run it.
     // Below is the function being CALLED if the response to the prompt is YES


  clearRange();  


   Logger.log('The user clicked "Yes."');
   } else {
   Logger.log('The user clicked "No" or the dialog\'s close button.');
   }  


}