In this article:

How to Make a Google Sheets Button [Ultimate Guide]

A Google Sheets button is an essential tool in your Google Sheets arsenal. Buttons in Google Sheets can be an awesome way to easily trigger custom scripts, greatly increasing speed and functionality.

We have already written some tutorials about adding and running custom scripts to Google Sheets in order to expand its functionality. One of these is about importing data from MySQL database to Google Sheets. The custom scripts can either run automatically or you can run them by typing the function name into the cell as an equation. Can we improve on this by, let's say, adding a button that we can click to run the script? Of course! We will learn how to do that in this tutorial. Are you ready?

How to Add a Button in Google Sheets

Step 1: Click Insert on the main menu, then click Drawing in the drop-down list. 

google sheets add button

The Drawing canvas will appear. 

add button to google sheets

Step 2: Click the Shape option. Several types of shapes will appear. After selecting the shape, draw it across the canvas to whatever size you want it to be.

create button in google sheets

Afterwards, click the Text box option to add a textbox over the button. Drag it to a certain size within the shape and then type the label that you want.

The button can look like as follows:

how to make a button in google sheets

Ultimately, the design of the button will be your choice, and given the range of shapes available in Google Sheets, you will not have a hard time finding the one that fits your idea.

Step 3: If you are satisfied with your button, click Save and Close

insert button google sheets

The button will now appear as an image in the Google Sheets. 

How to Assign Google Apps Script to Button

We will show you a quick example below, but click here to read our complete tutorial and FAQs for using a Google sheets button to run a script.

For this example, we will use the Google Apps script below:

var server = 'server_url';

var port = port_number;

var dbName = 'database_name';

var username = 'username';

var password = 'password';

var url = 'jdbc:mysql://'+server+':'+port+'/'+dbName;

 

function readData() {

 var conn = Jdbc.getConnection(url, username, password);

 var stmt = conn.createStatement();

 var results = stmt.executeQuery('SELECT * FROM table_title’);

 var metaData=results.getMetaData();

 var numCols = metaData.getColumnCount();

 var spreadsheet = SpreadsheetApp.getActive();

 var sheet = spreadsheet.getSheetByName('Sheet1');

 sheet.clearContents();

 var arr=[];

 

 for (var col = 0; col < numCols; col++) {

   arr.push(metaData.getColumnName(col + 1));

 }

 

 sheet.appendRow(arr);

 

while (results.next()) {

 arr=[];

 for (var col = 0; col < numCols; col++) {

   arr.push(results.getString(col + 1));

 }

 sheet.appendRow(arr);

}

 

results.close();

stmt.close();

sheet.autoResizeColumns(1, numCols+1);

Step 1: Click the three dots on the upper-right corner of the button. A drop-down list will appear. Click Assign script.

how to add a button in google sheets

Step 2: A pop-up box will appear, asking you what script you want to assign to the image. Type the function name, then click Ok.

assign script to button

You are now done! 

You can test it by clicking the image. The notification Running script will appear. 

Running script notification

When you run the script for the first time in that spreadsheet, you will receive a prompt that the script attached to this document needs your permission to run. Click Continue.

The add-ons created by third-party users for Google apps undergo a validation process by Google to ensure that the add-ons are not intended for malicious purposes by its creators. Click Advanced, then click Go to *name of your script* (unsafe).

unverified Google Apps Script Function

The usual procedure for permission requests will appear. Once done, the script will run. You can click the button again to make sure that the script runs as intended.

Button output

Voila!

Your button works. You can now use this to improve the dashboard you are creating in Google Sheets.  

Related Articles

-How to Create a Google Sheets Dashboard

-Automatically Send Emails from Google Sheets

We hope this article has helped you and given you a better understanding of how to make a Google Sheets button. You might also like our articles on how to assign a script to a button in Google Sheets and how to add a radio button in Google Sheets.

To optimize your workflow, we recommend reading our guide on how to send emails based on a date and trying our software to help you manage invoice reminders.

Schedule a free automation consult
Learn more

Automate repetitive tasks with Lido

Save hours on repetitive and tedious work. Lido is a new spreadsheet that connects your spreadsheets, forms, PDFs, and email inbox.

Trigger
Action
Select trigger
When a cell value in Google Sheets changes
Check Google Sheets for today's date
When a new row is added to Google Sheets
On new Google Form submission
Send me a daily reminder
On new Typeform submission
When a cell value in database changes
Check database for today's date
When a new row is added in database
When a new HubSpot customer is created
Select action
ADDCALENDAREVENT
Creates a one- or multiple-day calendar event with optional attendees
ADDHUBSPOT
Adds an object to Hubspot
ADDSLACKCHANNEL
Create a Slack channel, and optionally add a topic or members
CALLURL
Makes any HTTP request
CREATEGOOGLEDOC
Replaces [@column_name] values in a Google Doc with the corresponding table row's values
CREATEPDF
Replaces [@column_name] values in a Google Doc with the corresponding table row's values, then export it as a PDF
FETCH
Makes any HTTP request and returns the response
INSERTROWS
Inserts given array below defined values in given worksheet
SENDGMAIL
Sends an email using your Google account
SENDOUTLOOK
Sends an email using your Microsoft Outlook account
SENDSLACK
Sends a Slack message
SENDSMS
Sends an SMS message using your Twilio account
UPDATECELL
Updates cells with given values
UPDATEHUBSPOT
Updates a property of a Hubspot object
Trigger is required
Action is required
Get started