0
votes

the code i got it from & i ran the code as per the what the code indent to run the problem it the code runs for fixed no of rows & column i want to run it for any no of rows.It should take automatically based on the number of rows without specifying it the code since in this code we need to specify how number of rows to scanned & mailed to be send

Please help me if have any doubt please do sent you query to [email protected]

For your ref

https://developers.google.com/apps-script/articles/sending_emails

1

1 Answers

0
votes

About the tutorial code, one option to calculate the number of rows of the sheet is as follows:

function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process

  /* var numRows = 2;   // Number of rows to process */
  var numRows = sheet.getDataRange().getLastRow() - 1;

  // Fetch the range of cells A2:BX
  var dataRange = sheet.getRange(startRow, 1, numRows, 2)
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (i in data) {
    var row = data[i];
    var emailAddress = row[0];  // First column
    var message = row[1];       // Second column
    var subject = "Sending emails from a Spreadsheet";
    MailApp.sendEmail(emailAddress, subject, message);
  }
}

For a complete description of the API, visit Spreadsheet Services