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!
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.
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.
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.
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();
}
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With