Let’s see how this works with a simple example.
Imagine you have an invoice template you use on a regular basis, but it’s a pain to clear out all the values each time you need to start over. Well, you can add a button to Google Sheets so you can run scripts and clear your invoice with a single button click.
The user can enter information into cells B5, B8, E5 and E6 (shown in yellow).
In the script editor, accessed through Tools > Script Editor, add a very simple script to clear these specific cells out:
function clearInvoice() {
var sheet = SpreadsheetApp.getActiveSheet();
var invoiceNumber = sheet.getRange("B5").clearContent();
var invoiceAmount = sheet.getRange("B8").clearContent();
var invoiceTo = sheet.getRange("E5").clearContent();
var invoiceFrom = sheet.getRange("E6").clearContent();
}
You can run this function from the script editor and it will clear out the contents of the invoice.
But that’s a pain.
You don’t want to have to open up the script editor every time. You want to do that directly from your Google Sheet.
To do that, add a Google Sheets button. Homepage
You add a button via the Insert > Drawing menu.
This brings up the drawing editor where you can easily add a box and style it to look like a button:
Note: to edit or move the button after you’ve assigned it to a script, you now need to right-click on it.