[ACCEPTED]-I need a button to clear cells in a google spreadsheet-google-sheets

Accepted answer
Score: 29

Such script is very simple, you should look 2 at the tutorials to learn how to do it yourself.

Anyway, here 1 it is:

function clearRange() {
  //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
  sheet.getRange('B7:G7').clearContent();
}
Score: 10

To add a custom menu to your Google spreadsheet, that 2 when clicked, will list all your functions. See 1 the code below

function onOpen() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var menubuttons = [ {name: "Clear B7-G7", functionName: "clearRange1"},
                  {name: "Clear B13-G13", functionName: "clearRange2"}];
    ss.addMenu("Custom", menubuttons);
} // note you also have to have functions called clearRange1 and clearRange2 as list below
function clearRange1() { //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
  sheet.getRange('B7:G7').clearContent();
}
function clearRange2() { //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
  sheet.getRange('B13:G13').clearContent();
}

More Related questions