In this article:

How to Add a Script to Google Sheets (Easiest Way in 2024!)

December 5, 2024

Adding a script to Google Sheets is easy! In just a few clicks you can add any script. Simply follow the steps below.

Add Script to Google Sheets

1. Open your Google Sheets workbook

For this example, we will add a script to Google Sheets that allows you to automatically send emails. 

add script to google sheets

2. Go to Extensions > Apps Script

Apps Script is a tool created by Google that allows you to run code scripts in your spreadsheet . 

There are several things we can use Apps Script for such as creating new functions, adding custom menus or sidebars, building add-ons, integrating with other Google Workspace applications and a lot more. 

how to add script to google sheets

3. In the Script Editor, input your script

Our script for sending emails automatically would be:

function sendEmail() {

var ss = SpreadsheetApp.getActiveSpreadsheet()

var sheet1=ss.getSheetByName('Sheet1');

var sheet2=ss.getSheetByName('Sheet2');

var subject = sheet2.getRange(2,1).getValue();

var n=sheet1.getLastRow();

for (var i = 2; i < n+1 ; i++ ) {

var emailAddress = sheet1.getRange(i,2).getValue();

var name=sheet1.getRange(i,1).getValue();

var ServiceAcquired=sheet1.getRange(i,3).getValue();

var message = sheet2.getRange(2,2).getValue();

message=message.replace("<name>",name).replace("<service>",ServiceAcquired);

MailApp.sendEmail(emailAddress, subject, message);

}

}

This is how it would look like in our editor.

google sheets add script

Refer to our Send Emails Automatically In Google Sheets article for more information on how to edit this script and what it does.

4. Rename your Project and Save your Script.

You can name it however you want to and simply press the save icon to save it.

Script for sending Email in Google Sheets

5. Run Code and Grant Permissions

The run code button will be beside the save icon. This will then prompt you to grant access to your code since it is a custom and unknown script

Running Scripts in Google Sheets

To set up permissions: Click Review Permissions. Go to Advanced Settings -> Click “Go to Send Email” and allow the permissions. This will run your program and email your recipients.

Allowing Script to run

6. Now you will be able to run your script

Our script example will automatically send emails using Gmail based on our worksheet contents. We can see below how multiple emails were easily sent after running our script.

Sending Emails with Apps Script on Google Sheets

Using Apps Script, we can also use other scripts based on what we want to achieve with our data. Here are other Lido articles that will help you get started in automating with Google Sheets:

-Use Button to Run Script

-Connect MongoDB to Google Sheets with Script

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

To optimize your workflow, we recommend reading our guide on how to send bulk emails from 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 ->