Skip to content

Instantly share code, notes, and snippets.

@terrancesnyder
Created June 5, 2024 06:30
Show Gist options
  • Save terrancesnyder/aacce16eae677cd2ee904bb47660d65b to your computer and use it in GitHub Desktop.
Save terrancesnyder/aacce16eae677cd2ee904bb47660d65b to your computer and use it in GitHub Desktop.
send_email_on_row_change (Click on Extensions > Apps Script.)
function onEdit(e) {
// Get the range that was edited
var range = e.range;
var sheet = range.getSheet();
// Specify the column that triggers the email (e.g., column 3 is column C)
var triggerColumn = 3;
// Check if the edited column is the one we are interested in
if (range.getColumn() == triggerColumn) {
// Get the row of the edited cell
var row = range.getRow();
// Get the email address from a specific column (e.g., column 1 is column A)
var emailColumn = 1;
var emailAddress = sheet.getRange(row, emailColumn).getValue();
// Get the subject and body of the email
var subject = "Google Sheet Update Notification";
var body = "The value in column " + String.fromCharCode(64 + triggerColumn) + " has been changed to: " + range.getValue();
// Send the email
if (emailAddress) {
MailApp.sendEmail(emailAddress, subject, body);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment