2015-04-02 77 views
0

我很抱歉問這個問題,我一直在做這麼多的閱讀。該腳本確實完成,但不清除選定的單元格。我做錯了什麼?請幫忙?腳本沒有清除單元格

// 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(); 
    } 
+0

你是如何得到這段代碼運行的?你看到消息框嗎?有沒有更多的代碼沒有發佈? – ScampMichael 2015-04-02 14:34:38

+0

你想清除哪個細胞?在您的代碼上方您的代碼中,您提到了您的代碼給出單元格的選定單元格 – ScampMichael 2015-04-02 14:53:00

回答

1

Warning: unused function clearRange.
調用它:)
您定義的功能後,你缺少:
clearRange();

+0

謝謝,是的,彈出框並要求繼續。試圖清除a4到L120 – 2015-04-02 16:27:24

+0

是的,它修復了它 – 2015-04-02 16:32:14

+0

剛下班回家,我只是刪除該行嗎? – 2015-04-02 19:42:23

1

其他人一樣一直困擾於你所做的功能clearRange,但沒有在那裏你是否激活/調用它。以爲我會包含更改後的代碼,以便您可以看到調用該函數的含義。

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.'); 
    } 


}