In this article:

Create Button to Run a Script in Google Sheets [2024 Update]

December 5, 2024

In this article we will show you how to assign a script to a button in google sheets in just a few simple steps.

Add a Button to Run a Script in Google Sheets

Click here for our overview button on the Google Sheet Button.

1. Add a script via Google Apps Script

To access Google Apps Script, click Extension, then select Apps Script

google sheets add button to run script, click Extension then select apps script

A new tab will open where you can add the script.

google sheets add button to run script, apps script interface

Add the function in the space given. For example, we want a function that outputs “Hello world” in a pop-up box when a button is clicked. The function is as short as follows:

function myFunction() {

  Browser.msgBox("Hello World!");

}

google sheets add button to run script, apps script interface, function added

Click the Save button or press Ctrl+S on the keyboard to save the script.

Take note of the name of your function. We will need it in the next steps. For this example, the function is named myFunction, the default set by Google Apps Script.

2. Create a button

We need to create a figure that will serve as a button. Click Insert on the main menu, then select Drawing. 

google sheets create button to run script, click Insert then select Drawing

The drawing canvas will appear with some objects you can add to it. 

google sheets create button to run script, Drawing canvas

For our button, we will have a rounded rectangle with the label “Hello World!”. First, we click Shape.

google sheets create button to run script, Drawing canvas, shape highlighted

We can add a wide variety of shapes through this option. We will select the Rounded Rectangle

google sheets create button to run script, Drawing canvas, shapes shown, rounded rectangle highlighted 

Click and drag the cursor through the canvas to create the rounded rectangle in its desired size.

google sheets create button to run script, Drawing canvas, adding rounded rectangle screencap

google sheets create button to run script, Drawing canvas, rounded rectangle shown

We will now add the label “Hello World!” on top of it. Select the Text box from the main toolbar of the Drawing canvas.

google sheets create button to run script, Drawing canvas, text box highlighted

Click and drag the cursor through within the shape to create the rounded rectangle in its desired size.

google sheets create button to run script, Drawing canvas, button with label shown

Click Save and Close on the upper-right corner of the Drawing canvas. The drawing will appear on your active sheet.

google sheets create button to run script, created button shown

3. Resize and reposition the button

You can resize the button image before connecting it to a script. Here are the steps:

1. Click the image

2. Hold-click one of the blue boxes that appear on its borders

3. Drag the cursor until the preferred size of the button is achieved

google sheets create button to run script, resize button image

After resizing, you can reposition the button by clicking it and then dragging it to where you want it located:

google sheets create button to run script, change button image position

4. Connect the button to the script

Now that we have a button, we can connect the script to it. Hover your cursor over the button and a set of three dots will appear on its upper-right corner. Click it. 

A list of options will appear. Select Assign script.

assign script to button google sheets, click three dots on upper-right corner of button, assign script highlighted

A small box labeled Assign script will appear, asking you to input the script function. Type the function name set in the script. For our example, it’s simply the default myFunction.

assign script to button google sheets, assign script box, type function name in textbox

Once you have added the function name, click OK.

5. Authorize the script

As you will run the function for the first time, Google Sheets will ask you for authorization with a box labeled Authorization Required. Click Continue

google sheets button to run script, authorization required for the script to run

A new window will appear, allowing you to select the Google account associated with the spreadsheet containing the button. 

google sheets button to run script, choose account to authorize the script

After selecting the account, a warning will appear reminding you that Google has not verified the app. Click the small link on the lower-left corner labeled Advanced.

google sheets button to run script, google has not verified this app warning

Another reminder will appear to continue only if you understand the risks and trust the developer. Click Go to Untitled project (unsafe) or whatever the project name is in Google Apps Script.

google sheets button to run script, google hasnt verified this app warning, link to continue using it appears

A new page will appear listing the permissions needed by the script. Click Allow

google sheets button to run script, list of permissions needed by the script shown

Voila! The button will now run your script.

google sheets button to run script, button functioning to run script

FAQs

Do I Need to Authorize the Script Every Time I Use the Button?

No. You only need to do this once for every script, and in the subsequent clicks on the button the script will automatically run. 

Can I Use an Image as a Button to Run The Script in Google Sheets?

Yes! The same three dots will appear on the upper-right corner of the image when you hover your cursor over it. Select Assign script just like what has been highlighted in the previous steps.

google sheets button to run script, image set as button

Just make sure that when you insert the image, select Insert image over cells.

google sheets add button to run script, insert image over cells highlighted

Can I Resize and Reposition the Button After I Assign A Script?

Yes. Follow Step 3 but instead of a left click, you can either right-click the button or hold Ctrl then left-click the button. 

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

To optimize your workflow, we recommend reading our guide on how to set reminders in Google Sheets.

Get Google Sheets productivity and automation tips delivered straight to your inbox
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
We'll email you 1-3 times a week — and never share your information.

Work less, automate more!

Use Lido to connect your spreadsheets to email, Slack, calendars, and more to automate data transfers and eliminate manual copying and pasting. View all use cases ->