I've built a spreadsheet to automate sending formulaic emails. It sends to the client's email (defined in spreadsheet) and CCs an email address that needs to receive all projects. The number of projects/emails will change each time I use the sheet.
I've run into trouble because the blank rows in the spreadsheet currently trigger emails to the CC email address. I don't think I can use something like getLastRow
to fix this because I have formulas in every cell in some columns. Can you help me figure out how to only send an email if there is data in Column A?
Here is my current script:
function uploadsender() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A2:AA");
var UserData = range.getValues();
for (i in UserData) {
var row = UserData[i];
var emailaddress = row[2];
var bccaddress = row[3];
var subject = row[4];
var comments = row[5];
var filenames = row[7];
MailApp.sendEmail(emailaddress, subject, filenames + "\n\n" + comments, {
cc: "example@gmail.com",
bcc: bccaddress,
name: "John Doe"}
);
}
}
It seems like something like this answer might be my solution:
var Avals = ss.getRange("A1:A").getValues();
var Alast = Avals.filter(String).length;
But I assume this will conflict with lines 3 and 4 of my current script?