How to Add a Script to Google Sheets (Easiest Way in 2023!)
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.

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.

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.

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.

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

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.

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.

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: