Gerard Lamoureux
Gerard Lamoureux

Reputation: 3

I need to stop my Script on an Blank cell

Can you help me to stop de script if cell B2 is empty? I need to stop my Script on an Blank cell but i want to show B18 in the sheet in red to advise de script stopped.

I am not good in Script, i almost begin....

 function BlankCell(){

var Cell = SpreadsheetApp.getActiveSheet().getRange(2, 1);

if (Cell.isBlank()); 

var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('B18').setBackground('#bb0b0b');


if (Cell.getValue());{


   var sheet = SpreadsheetApp.getActiveSheet();
   var range = sheet.getRange(1, 1);  // Fetch the range of cells B1:B1
   var subject = range.getValues();   // Fetch value for subject line from above range
   var range = sheet.getRange(1, 9);  // Fetch the range of cells I1:I1
   var numRows = range.getValues();   // Fetch value for number of emails from above range
   var startRow = 4;                  // First row of data to process
   var dataRange = sheet.getRange(startRow, 1, numRows,9 ) // Fetch the range of cells A4:I_
   var data = dataRange.getValues();  // Fetch values for each row in the Range.
   for (i in data) {
      var row = data[i];
      var emailAddress = row[0];      // First column
      var message = row[8];           // Ninth column
      MailApp.sendEmail(emailAddress, subject, message);

      var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('C25').setBackground('#00ff00');



   }


}
}

Upvotes: 0

Views: 700

Answers (1)

Alexasks
Alexasks

Reputation: 113

I think you need to include an IF statement so if a variable is blank do not run

if (emailAddress != "") { //Prevents sending duplicates and email to blank cells

Not sure if this will help

Regards

Upvotes: 1

Related Questions