Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need a button to clear cells in a google spreadsheet [closed]

Im making a tool for myself with Google Spreadsheets, and as part of that tool I would like to have a button that clears a specific set of cells. As I understand it, I need to insert a drawing, and then assign a script to that drawing. Trouble is, I dont know the first thing about writing my own so, im here looking for help!

The end goal of this would be for me to have a drawing with a script attached to it that would, when activated, clear the data (make them blank, but leave the color) from cells B7-G7.

Any help you guys could offer would be fantastic!

like image 636
user1207825 Avatar asked Feb 13 '12 21:02

user1207825


People also ask

How do I create a button in Google Sheets?

You add a button via the Insert > Drawing menu. When you click Save and Close, this drawing gets added to your Google Sheet. You can click on it to resize it or drag it around to reposition it. Then type in the name of the function you want to run from your Apps Script code.

Is there a clear contents option in Google Sheets?

Select one or more cells and press Delete or Backspace to clear the current contents. You can also right-click a cell and select Clear Contents.

Where is clear on Google Sheets?

Clear Contents in Google Sheets To clear all formatting, select the same range (B4:E4), and in the Menu, go to Format > Clear formatting (or use the keyboard shortcut CTRL + \). Now, all content and formatting are cleared from the selected range of cells.


2 Answers

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

Anyway, here it is:

function clearRange() {
  //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
  sheet.getRange('B7:G7').clearContent();
}
like image 106
Henrique G. Abreu Avatar answered Nov 26 '22 12:11

Henrique G. Abreu


To add a custom menu to your Google spreadsheet, that when clicked, will list all your functions. See 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();
}
like image 45
Bubz Avatar answered Nov 26 '22 11:11

Bubz