0
votes

I have looked on SO and researched my many questions on Google, but did not find anything that provided a direct answer. I am setting up code to email a sheet one (or many) times. I am having trouble setting the email address of the recipient(s). I need the script to send out one email for each address in the data range (P122:P126).

I regret that, for privacy reasons, I am unable to share the entire script. (On a positive note, everything except this works.)

The active sheet is "var sourceSheet" The number of email addresses is a number in cell S121 on the active sheet All of the email addresses needed are in a vertical column on the active sheet ("P122:P126")

Here is the relevant section of code:

  // Sets the recipient of the email message
    
  var numRows = sourceSheet.getRange("S121:S121").getValues();  // Number of rows to process
  // Fetch the range of cells P122:P126 that contain email addresses
  var dataRange = sourceSheet.getRange(122,16,numRows,1);
  // Fetch values for each row in the Range.

What needs to be done to obtain one (or more) email addresses usable by the "GmailApp.sendEmail" statement? No matter how I analyze the problem, it seems to me (and I may be wrong) that a loop is necessary, and I don't know how to use the information I have to create the actions needed.

1

1 Answers

0
votes

Try this:

 var numRows=sourceSheet.getRange("S121").getValue();
 var dataRange=sourceSheet.getRange(122,16,numRows,1);