# Help with Google Sheets Script

**URL:** https://community.glideapps.com/t/help-with-google-sheets-script/22084
**Category:** Ask for Help
**Created:** [February 1, 2021, 9:24pm UTC](https://community.glideapps.com/t/help-with-google-sheets-script/22084 "2021-02-01T21:24:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![drascon](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/drascon/32/20070_2.png) [@drascon](https://community.glideapps.com/u/drascon)
#### Post date: [February 1, 2021, 9:24pm UTC](https://community.glideapps.com/t/help-with-google-sheets-script/22084/1 "2021-02-01T21:24:37Z")

</div>

Can someone please help me with this script? It works exactly how I need it to but I need it to add more than the first two columns in the row when the email is sent. I tried duplicating and changing the row numbers in the “var message = row[_x_];” but it didn’t work.

var EMAIL\_SENT = ‘EMAIL\_SENT’;  
function sendEmails2() {  
var sheet = SpreadsheetApp.getActiveSheet();  
var startRow = 2; // First row of data to process  
var numRows = 2; // Number of rows to process  
// Fetch the range of cells A2:B3  
var dataRange = sheet.getRange(startRow, 1, numRows, 3);  
// Fetch values for each row in the Range.  
var data = dataRange.getValues();  
for (var i = 0; i \< data.length; ++i) {  
var row = data[i];  
var emailAddress = row[0]; // First column  
var message = row[1]; // Second column  
var emailSent = row[2]; // Third column  
if (emailSent !== EMAIL\_SENT) { // Prevents sending duplicates  
var subject = ‘A Feedback Form Was Submitted using the REMSA app’;  
MailApp.sendEmail(emailAddress, subject, message);  
sheet.getRange(startRow + i, 3).setValue(EMAIL\_SENT);  
// Make sure the cell is updated right away in case the script is interrupted  
SpreadsheetApp.flush();  
}  
}  
}

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [February 2, 2021, 11:24am UTC](https://community.glideapps.com/t/help-with-google-sheets-script/22084/2 "2021-02-02T11:24:34Z")

</div>

This line:

```auto
var dataRange = sheet.getRange(startRow, 1, numRows, 3);

```

addresses a range that is 3 columns wide.  
If you want extra columns, change the 3 in that line to something else.  
You can then address those extra columns further down…

```auto
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var emailSent = row[2]; // Third column
var blah = row[3]; // Fourth column
var moo = row[4]; // Fifth column
etc, etc...

```

---

<div class="post-metadata">

### Author: ![drascon](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/drascon/32/20070_2.png) [@drascon](https://community.glideapps.com/u/drascon)
#### Post date: [February 2, 2021, 4:11pm UTC](https://community.glideapps.com/t/help-with-google-sheets-script/22084/3 "2021-02-02T16:11:14Z")

</div>

I knew I was missing something! Thank you!!!

---

<div class="post-metadata">

### Author: ![NoCodeAndy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nocodeandy/32/62530_2.png) [@NoCodeAndy](https://community.glideapps.com/u/NoCodeAndy)
#### Post date: [January 17, 2024, 4:53pm UTC](https://community.glideapps.com/t/help-with-google-sheets-script/22084/4 "2024-01-17T16:53:43Z")

</div>


