+ Reply to Thread
Results 1 to 2 of 2

Sending auto Email based on given data

  1. #1
    Registered User
    Join Date
    07-29-2020
    Location
    Pakistan
    MS-Off Ver
    2016, 365
    Posts
    20

    Question Sending auto Email based on given data

    I was using the below script to send an auto emails through Sheet "Reference" whenever any data is filled by Google form into sheet "Data".

    I do not know how to make a loop to do this task that whenever any data is updated on sheet "Data" from Google form then automatically an email has been sent to the mail available in "Reference" sheet Col"G" after sending the email to that particular entity, code should mention in "Reference" sheet Col"N" as Mail sent.

    "Reference" sheet Col"O" is Notification Text "Reference" sheet Col"M" is subject "Reference" sheet Col"G" is such email where code will send above mentioned data

    Code should not sent email again on those ID's in "Reference" sheet Col"N" where on "Email Sent" i mentioned.

    Sheet Link https://docs.google.com/spreadsheets...zjA/edit#gid=0

    function sendEmails2() {
    var sheet = SpreadsheetApp.getActiveSpreadsheet();
    var sheetname= sheet.getSheetByName("Reference");
    var startRow = 2; // First row of data to process
    var numRows = sheetname.getLastRow("Reference"); // Number of rows to process
    // Fetch the range of cells A2:B3
    var dataRange = sheetname.getRange(startRow, 1, numRows, 15);
    // 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[6]; // First column
    var message = row[13]; // Second column
    var emailSent = row[14]; // Third column
    if (emailSent !== EMAIL_SENT && row[12] == "Mail Send" && row[6] != "") { // Prevents sending duplicates
    var subject = row[11];
    MailApp.sendEmail(emailAddress, subject, message);
    sheetname.getRange(startRow + i, 15).setValue(EMAIL_SENT);
    // Make sure the cell is updated right away in case the script is interrupted
    SpreadsheetApp.flush();
    }
    }
    }

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Sending auto Email based on given data

    Administrative Note:

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Auto Outlook Signature of users sending the email
    By E5254730 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-18-2020, 08:44 AM
  2. [SOLVED] Auto sending email from Excel
    By jimmisavage in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-20-2020, 09:42 AM
  3. Auto-select correct sending account when replying to a forwarded email?
    By twilsonco in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2016, 01:32 AM
  4. Auto sending email reminders to clients from excel
    By HGV in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2014, 11:33 AM
  5. Replies: 2
    Last Post: 09-22-2012, 01:18 PM
  6. Auto email generation and sending through outlook before one month of contract end da
    By kumar_shri in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-24-2011, 06:18 AM
  7. auto sending email before due date via excel 2003
    By AsifShabbir in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 03-02-2011, 09:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1