Ok, progress is being made: I have managed to get the form entries to be written to the spreadsheet and it is working except the last entry is being entered twice. Any ideas what I am doing wrong anyone?
The amended code is:
function InsertDataInSheet(e) //Function to insert data into spreadsheet on clicking submit
{
var app = UiApp.getActiveApplication();
//get number of rows to input
var num = parseInt(e.parameter.table_tag);
var num = num+1;
//set increment step through
for (var i = 1; i < num ; i++ ) {
//Declare varialbe fields to collect data from
var user = Session.getActiveUser().getEmail();
var date = e.parameter['DateBox'+i];
var location = e.parameter['LocationListBox'+i];
var source = e.parameter['SourceListBox'+i];
var reporter = e.parameter['ReporterTextBox'+i];
var priority = e.parameter['PriorityListBox'+i];
var hazard = e.parameter['HazardListBox'+i];
var details = e.parameter['DetailsTextBox'+i];
var description = e.parameter['DescriptionTextBox'+i];
var timeStamp = new Date();
//Decide date that this needs to be closed by
if (priority === '02 - WITHIN 24-48 HOURS') {
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+2);
var actiondate = dateTemp;
}
if (priority === '03 - WITHIN 1 WEEK') {
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+7);
var actiondate = dateTemp;
}
if (priority === '04 - WITHIN 1 MONTH') {
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+31);
var actiondate = dateTemp;
}
if (priority === '05 - WITHIN 3 MONTHS') {
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+90);
var actiondate = dateTemp;
}
if (priority === '06 - FOR MANAGEMENT DISCUSSION') {
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+365);
var actiondate = dateTemp;
}
//establish email addresses
//Declare correct range to obtain values
var LocationSheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("LocationCodes")
//Start with central maintenance department
var email00 = LocationSheet.getRange(33,5).getValue()
//followed by other emails as they appear
var email01 = LocationSheet.getRange(3,5).getValue();
var email02 = LocationSheet.getRange(4,5).getValue();
var email03 = LocationSheet.getRange(5,5).getValue();
var email04 = LocationSheet.getRange(6,5).getValue();
var email05 = LocationSheet.getRange(7,5).getValue();
var email06 = LocationSheet.getRange(8,5).getValue();
var email07 = LocationSheet.getRange(9,5).getValue();
var email08 = LocationSheet.getRange(10,5).getValue();
var email09 = LocationSheet.getRange(11,5).getValue();
var email10 = LocationSheet.getRange(12,5).getValue();
var email11 = LocationSheet.getRange(13,5).getValue();
var email12 = LocationSheet.getRange(14,5).getValue();
var email13 = LocationSheet.getRange(15,5).getValue();
var email14 = LocationSheet.getRange(16,5).getValue();
var email15 = LocationSheet.getRange(17,5).getValue();
var email16 = LocationSheet.getRange(18,5).getValue();
var email17 = LocationSheet.getRange(19,5).getValue();
var email18 = LocationSheet.getRange(20,5).getValue();
var email19 = LocationSheet.getRange(21,5).getValue();
var email20 = LocationSheet.getRange(22,5).getValue();
//declare the correct Depots to check
var LocationSheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("LocationCodes");
var depot01 = LocationSheet.getRange(3,4).getValue();
var depot02 = LocationSheet.getRange(4,4).getValue();
var depot03 = LocationSheet.getRange(5,4).getValue();
var depot04 = LocationSheet.getRange(6,4).getValue();
var depot05 = LocationSheet.getRange(7,4).getValue();
var depot06 = LocationSheet.getRange(8,4).getValue();
var depot07 = LocationSheet.getRange(9,4).getValue();
var depot08 = LocationSheet.getRange(10,4).getValue();
var depot09 = LocationSheet.getRange(11,4).getValue();
var depot10 = LocationSheet.getRange(12,4).getValue();
var depot11 = LocationSheet.getRange(13,4).getValue();
var depot12 = LocationSheet.getRange(14,4).getValue();
var depot13 = LocationSheet.getRange(15,4).getValue();
var depot14 = LocationSheet.getRange(16,4).getValue();
var depot15 = LocationSheet.getRange(17,4).getValue();
var depot16 = LocationSheet.getRange(18,4).getValue();
var depot17 = LocationSheet.getRange(19,4).getValue();
var depot18 = LocationSheet.getRange(20,4).getValue();
var depot19 = LocationSheet.getRange(21,4).getValue();
var depot20 = LocationSheet.getRange(22,4).getValue();
//if source is recorded as '08 - Maitenance Request System', the recipient is maintenance deparment
if (source === "08 - Maintenance Request System"){
var recipient = email00;
//or depots as listed
} else if(location === depot01){
var recipient = email01;
} else if(location === depot02){
var recipient = email02;
} else if(location === depot03){
var recipient = email03;
} else if(location === depot04){
var recipient = email04;
} else if(location === depot05){
var recipient = email05;
} else if(location === depot06){
var recipient = email06;
} else if(location === depot07){
var recipient = email07;
} else if(location === depot08){
var recipient = email08;
} else if(location === depot09){
var recipient = email09;
} else if(location === depot10){
var recipient = email10;
} else if(location === depot11){
var recipient = email11;
} else if(location === depot12){
var recipient = email12;
} else if(location === depot13){
var recipient = email13;
} else if(location === depot14){
var recipient = email14;
} else if(location === depot15){
var recipient = email15;
} else if(location === depot16){
var recipient = email16;
} else if(location === depot17){
var recipient = email17;
} else if(location === depot18){
var recipient = email18;
} else if(location === depot19){
var recipient = email19;
} else if(location === depot20){
var recipient = email20;
} else {
//and send an email to the error catch all if no code supplied
var recipient = email00; //change as necessary
}
var sheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName('LOG');
var lastRow = sheet.getLastRow();
var lrp1 = lastRow+1
var targetRange = sheet.getRange(lastRow+1, 1, 1, 12).setValues([[timeStamp,date,source,location,reporter,user,hazard,details,description,priority,recipient,actiondate]]);
}
var sheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("LOG");
var lastRow = sheet.getLastRow();
var lrp1 = lastRow+1
//Amend [getRange(lastRow+1, 1, 1, **)] integer to reflet number of headers being written if more added
var targetRange = sheet.getRange(lastRow+1, 1, 1, 12).setValues([[timeStamp,date,source,location,reporter,user,hazard,details,description,priority,recipient,actiondate]]);
var Body = 'A new [' +source+ '] log entry has been recorded at [' +location+ '], listed as [' + hazard+ ']. This form was submitted by [' +user+ '] with the timestamp [' +timeStamp+ '].'
}
I have not got any further, so I am breaking the question in to two. This is part 1. My code is still failing and it is because (if I understand Sandy correctly (thanks again btw)) there is no loop.
The code writes what I need in the right order I need it, it just doesn't write a new row for each entry - I only get the first row written.
Any help greatly appreciated.
The pseudocode reads like this:
Create a form for filling out a form embedded in a website.
Create + & - buttons for adding or removing rows as required.
If + clicked add row.
If - clicked remove row.
When submit clicked, open the spreadsheet and write a new row of data for every row created in the form.
Once submitted create a notification page.
The code I have so far is:
//spreadsheet key is needed to access the correct spreadsheet. It is located AFTER "/d/" and before "/edit" in the URL
var itemSpreadsheetKey = '1mgp5d6gZydrn-bI6KfCNNOsIj9sh0dLJMzVq4Al4ypY';
var LogSheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("Log");
var LocationSheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("LocationCodes");
var HazardSheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("HazardCodes");
var SourceSheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("SourceCodes");
function doGet() //the 'doGet' function retrieves the code from the embedded URL in the gadget
{
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var table = app.createFlexTable().setId('table').setTag('0').setBorderWidth(0);
//Write the header for the table
var headerArray = ['DATE' , 'DEPOT/SITE' , 'REPORTER', 'SOURCE CODE', 'HAZARD CODE' , 'BRIEF DETAILS' , 'FULL DESCRIPTION' , 'PRIORITY'];
for(var i=0; i<headerArray.length; i++)
{
table.setWidget(0, i, app.createLabel(headerArray[i]));
}
//Add the first row of form elements to input Member information
addMemberRow(app);
//Add a button to submit the info
var button = app.createSubmitButton('CLICK TO SUBMIT');
// call the InsertDataInSheet routine
var handler = app.createServerHandler('InsertDataInSheet');
handler.addCallbackElement(panel);
button.addMouseUpHandler(handler);
panel.add(table)
.add(button);
app.add(panel);
return app;
}
function InsertDataInSheet(e) //Function to insert data in the sheet on clicking the submit button
{
var app = UiApp.getActiveApplication();
//get input values from last row of data
var num = parseInt(e.parameter.table_tag);
var num = num+1;
//Set increment value to step through
for (var i = 1; i < num ; i++ )
{
//Declare variable fields to collect data from
var user = Session.getActiveUser().getEmail();
var date = e.parameter['DateBox'+i];
var location = e.parameter['LocationListBox'+i];
var source = e.parameter['SourceListBox'+i];
var reporter = e.parameter['ReporterTextBox'+i];
var priority = e.parameter['PriorityListBox'+i];
var hazard = e.parameter['HazardListBox'+i];
var details = e.parameter['DetailsTextBox'+i];
var description = e.parameter['DescriptionTextBox'+i];
var user = Session.getUser().getUserLoginId();
var timeStamp = new Date();
//Decide date that this needs to be closed by
if (priority === '02 - WITHIN 24-48 HOURS')
{
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+2);
var actiondate = dateTemp;
}
if (priority == '03 - WITHIN 1 WEEK')
{
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+7);
var actiondate = dateTemp;
}
if (priority == '04 - WITHIN 1 MONTH')
{
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+31);
var actiondate = dateTemp;
}
if (priority == '05 - WITHIN 3 MONTHS')
{
var dateTemp = new Date(date);
dateTemp.setDate(dateTemp.getDate()+90);
var actiondate = dateTemp;
}
if (priority == '06 - FOR MANAGEMENT DISCUSSION')
{
var actiondate = "N/A";
}
app = UiApp.getActiveApplication().remove(0);
app.createVerticalPanel()
.setId('info')
.setVisible(true)
.setStyleAttribute('left', 0)
.setStyleAttribute('top', 0)
.setStyleAttribute('zIndex', '1')
.setStyleAttribute('position', 'fixed')
.setStyleAttribute('background', 'white')
.setHeight('400px')
.setStyleAttribute('text-align', 'center')
.setBorderWidth(0)
.setWidth('500px');
app.add(app.createLabel(''));
app.add(app.createLabel('Thank you. Your form has been submitted to the Proactive/Reactive Hazard Logging database and ' +recipient+ ' (the Health & Safety Site Coordinator) has been alerted.'));
app.add(app.createLabel('A copy of this email has been sent to ' +user+ ' with the timestamp ' +timeStamp+ ' which should be quoted if follow up is required.'));
app.add(app.createLabel('Please refresh this page to add submit another form, or close the page to exit'));
return app.close();
}
//establish email addresses
//Declare correct range to obtain values
var LocationSheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("LocationCodes")
//Start with central maintenance department
var email00 = LocationSheet.getRange(33,5).getValue()
//followed by other emails as they appear
var email01 = LocationSheet.getRange(3,5).getValue();
var email02 = LocationSheet.getRange(4,5).getValue();
var email03 = LocationSheet.getRange(5,5).getValue();
var email04 = LocationSheet.getRange(6,5).getValue();
var email05 = LocationSheet.getRange(7,5).getValue();
var email06 = LocationSheet.getRange(8,5).getValue();
var email07 = LocationSheet.getRange(9,5).getValue();
var email08 = LocationSheet.getRange(10,5).getValue();
var email09 = LocationSheet.getRange(11,5).getValue();
var email10 = LocationSheet.getRange(12,5).getValue();
var email11 = LocationSheet.getRange(13,5).getValue();
var email12 = LocationSheet.getRange(14,5).getValue();
var email13 = LocationSheet.getRange(15,5).getValue();
var email14 = LocationSheet.getRange(16,5).getValue();
var email15 = LocationSheet.getRange(17,5).getValue();
var email16 = LocationSheet.getRange(18,5).getValue();
var email17 = LocationSheet.getRange(19,5).getValue();
var email18 = LocationSheet.getRange(20,5).getValue();
var email19 = LocationSheet.getRange(21,5).getValue();
var email20 = LocationSheet.getRange(22,5).getValue();
//declare the correct Depots to check
var LocationSheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("LocationCodes");
var depot01 = LocationSheet.getRange(3,4).getValue();
var depot02 = LocationSheet.getRange(4,4).getValue();
var depot03 = LocationSheet.getRange(5,4).getValue();
var depot04 = LocationSheet.getRange(6,4).getValue();
var depot05 = LocationSheet.getRange(7,4).getValue();
var depot06 = LocationSheet.getRange(8,4).getValue();
var depot07 = LocationSheet.getRange(9,4).getValue();
var depot08 = LocationSheet.getRange(10,4).getValue();
var depot09 = LocationSheet.getRange(11,4).getValue();
var depot10 = LocationSheet.getRange(12,4).getValue();
var depot11 = LocationSheet.getRange(13,4).getValue();
var depot12 = LocationSheet.getRange(14,4).getValue();
var depot13 = LocationSheet.getRange(15,4).getValue();
var depot14 = LocationSheet.getRange(16,4).getValue();
var depot15 = LocationSheet.getRange(17,4).getValue();
var depot16 = LocationSheet.getRange(18,4).getValue();
var depot17 = LocationSheet.getRange(19,4).getValue();
var depot18 = LocationSheet.getRange(20,4).getValue();
var depot19 = LocationSheet.getRange(21,4).getValue();
var depot20 = LocationSheet.getRange(22,4).getValue();
//if source is recorded as '08 - Maitenance Request System', the recipient is maintenance deparment
if (source === "08 - Maintenance Request System"){
var recipient = email00;
//or depots as listed
} else if(location === depot01){
var recipient = email01;
} else if(location === depot02){
var recipient = email02;
} else if(location === depot03){
var recipient = email03;
} else if(location === depot04){
var recipient = email04;
} else if(location === depot05){
var recipient = email05;
} else if(location === depot06){
var recipient = email06;
} else if(location === depot07){
var recipient = email07;
} else if(location === depot08){
var recipient = email08;
} else if(location === depot09){
var recipient = email09;
} else if(location === depot10){
var recipient = email10;
} else if(location === depot11){
var recipient = email11;
} else if(location === depot12){
var recipient = email12;
} else if(location === depot13){
var recipient = email13;
} else if(location === depot14){
var recipient = email14;
} else if(location === depot15){
var recipient = email15;
} else if(location === depot16){
var recipient = email16;
} else if(location === depot17){
var recipient = email17;
} else if(location === depot18){
var recipient = email18;
} else if(location === depot19){
var recipient = email19;
} else if(location === depot20){
var recipient = email20;
} else {
//and send an email to the error catch all if no code supplied
var recipient = email00; //change as necessary
}
var sheet = SpreadsheetApp.openById(itemSpreadsheetKey).getSheetByName("LOG");
var lastRow = sheet.getLastRow();
var lrp1 = lastRow+1
//Amend [getRange(lastRow+1, 1, 1, **)] integer to reflet number of headers being written if more added
var targetRange = sheet.getRange(lastRow+1, 1, 1, 12).setValues([[timeStamp,date,source,location,reporter,user,hazard,details,description,priority,recipient,actiondate]]);
var Body = 'A new [' +source+ '] log entry has been recorded at [' +location+ '], listed as [' + hazard+ '], please visit > http://goo.gl/LRjPI9 < for further details. This form was submitted by [' +user+ '] with the timestamp [' +timeStamp+ '].'
}
function addMemberRow(app) //Function adds new rows to enable multiple form entries
{
var table = app.getElementById('table');
var tag = parseInt(table.getTag());
var numRows = tag+1;
if(numRows >1){
//Row is same, as last row drops back one.
table.removeCell(numRows-1, 8);
table.removeCell(numRows-1, 8);
}
//Create date picker box
var DateBox = app.createDateBox().setWidth('50px').setId('DateBox'+numRows).setName('DateBox'+numRows).setFormat(UiApp.DateTimeFormat.DATE_SHORT);
// Create 'locations' List with drop down selections
var LocationListBox = app.createListBox().setWidth('100px').setId('LocationListBox'+numRows).setName('LocationListBox'+numRows);
LocationListBox.addItem('');
LocationListBox.addItem('BH - COMPANY (H&S Projects Team)');
LocationListBox.addItem('CS - Conway Street Depot');
LocationListBox.addItem('CT - Crawley Travel Office');
LocationListBox.addItem('CY - Crawley Depot');
LocationListBox.addItem('DU - Durrington Outstation');
LocationListBox.addItem('EB - Eastbourne Outstation');
LocationListBox.addItem('HS - Horsham Crew Area');
LocationListBox.addItem('LR - Lewes Road Depot');
LocationListBox.addItem('NE - Newhaven Engineering');
LocationListBox.addItem('NO - Newhaven Outstation');
LocationListBox.addItem('OS - One Stop Travel - North Street');
LocationListBox.addItem('RH - Redhill Bus Station');
LocationListBox.addItem('UK - Uckfield Outstation');
LocationListBox.addItem('VP - Vehicles Procurement (Budget)');
LocationListBox.addItem('WK - Whitehawk Depot');
// Create 'Source Code' list with drop down selections
var SourceListBox = app.createListBox().setWidth('100px').setId('SourceListBox'+numRows).setName('SourceListBox'+numRows);
SourceListBox.addItem('');
SourceListBox.addItem('01 - Accident/Incident investigations & reports');
SourceListBox.addItem('02 - Company or location H&S Committee/Forum actions');
SourceListBox.addItem('03 - Emergency Preparedness reviews/activities');
SourceListBox.addItem('04 - Employee Hazard / Near Miss Reporting System');
SourceListBox.addItem('05 - Fire Brigade visit actions');
SourceListBox.addItem('06 - Group H&S audit actions');
SourceListBox.addItem('07 - Internal general & speicific location monitoring processes');
SourceListBox.addItem('08 - Maintenance Request System');
SourceListBox.addItem('09 - Management/employee meetings/toolbox talks & questions');
SourceListBox.addItem('10 - Planned Preventative Maintenance activities');
SourceListBox.addItem('11 - Regulatory bodies visit actions');
SourceListBox.addItem('12 - Statutory & other specific inspection/testing actions');
SourceListBox.addItem('Other');
// Create text box for entering 'Reporters' name
var ReporterTextBox = app.createTextBox().setWidth('100px').setId('ReportertTextBox'+numRows).setName('ReporterTextBox'+numRows);
// Create 'Priority Code' list with drop down selections
var PriorityListBox = app.createListBox().setWidth('100px').setId('PriorityListBox'+numRows).setName('PriorityListBox'+numRows);
PriorityListBox.addItem('');
PriorityListBox.addItem('02 - WITHIN 24-48 HOURS');
PriorityListBox.addItem('03 - WITHIN 1 WEEK');
PriorityListBox.addItem('04 - WITHIN 1 MONTH');
PriorityListBox.addItem('05 - WITHIN 3 MONTHS');
PriorityListBox.addItem('06 - FOR MANAGEMENT DISCUSSION');
// Create 'Hazard Box' list with drop down selection
var HazardListBox = app.createListBox().setWidth('100px').setId('HazardListBox'+numRows).setName('HazardListBox'+numRows);
HazardListBox.addItem('');
HazardListBox.addItem('01 - Access Equipment Fault');
HazardListBox.addItem('02 - Assault - verbal/physical');
HazardListBox.addItem('03 - Blocked/held open fire route/exit');
HazardListBox.addItem('04 - Contractor/visitor non-compiance or poor/unsafe practice');
HazardListBox.addItem('05 - Fire/emergency related');
HazardListBox.addItem('06 - First Aid provision');
HazardListBox.addItem('07 - Fork Lift Truck operation');
HazardListBox.addItem('08 - Housekeeping & Spillages');
HazardListBox.addItem('09 - Lifting Equipment');
HazardListBox.addItem('10 - Lighting Fault');
HazardListBox.addItem('11 - Manual Handling');
HazardListBox.addItem('12 - Missing/unclear information/warning/directional signage');
HazardListBox.addItem('13 - Occupational Health related item');
HazardListBox.addItem('14 - Pit safety equipment/barriers missing/poorly in place');
HazardListBox.addItem('15 - Road Traffic Accident');
HazardListBox.addItem('16 - Slips, trips & falls');
HazardListBox.addItem('17 - Staff non-compliance (e.g. PPE) or poor/unsafe practice');
HazardListBox.addItem('18 - Washroom/mess rooms facilities/housekeeping ');
HazardListBox.addItem('19 - Work equipment fault');
HazardListBox.addItem('20 - Workplace transport movement');
// Create 'Details Box' for recording the hazard/defect
var DetailsTextBox = app.createTextArea().setWidth('150px').setId('DetailsTextBox'+numRows).setName('DetailsTextBox'+numRows);
// Create 'Description Box' for giving further details
var DescriptionTextBox = app.createTextArea().setWidth('150px').setId('DescriptionTextBox'+numRows).setName('DescriptionTextBox'+numRows);
//Add to page
table.setWidget(numRows, 0, DateBox)
.setWidget(numRows, 1, LocationListBox)
.setWidget(numRows, 2, ReporterTextBox)
.setWidget(numRows, 3, SourceListBox)
.setWidget(numRows, 4, HazardListBox)
.setWidget(numRows, 5, DetailsTextBox)
.setWidget(numRows, 6, DescriptionTextBox)
.setWidget(numRows, 7, PriorityListBox)
table.setTag(numRows.toString());
addButtons(app);
}
function addButtons(app) //add or remove buttons as required
{
var table = app.getElementById('table');
var numRows = parseInt(table.getTag());
//Create handler to add/remove row
var addRemoveRowHandler = app.createServerHandler('_addRemoveRow');
addRemoveRowHandler.addCallbackElement(table);
//Add row button and handler
var addRowBtn = app.createButton('+').setId('addOne').setTitle('Add row');
table.setWidget(numRows, 8, addRowBtn);
addRowBtn.addMouseUpHandler(addRemoveRowHandler);
//remove row button and handler
var removeRowBtn = app.createButton('-').setId('removeOne').setTitle('Remove row');
table.setWidget(numRows, 9, removeRowBtn);
removeRowBtn.addMouseUpHandler(addRemoveRowHandler);
}
function _addRemoveRow(e) //add or remove rows as required
{
var app = UiApp.getActiveApplication();
var table = app.getElementById('table');
var tag = parseInt(e.parameter.table_tag);
var source = e.parameter.source;
if(source == 'addOne'){
table.setTag(tag.toString());
addMemberRow(app);
}
else if(source == 'removeOne'){
if(tag > 1){
//Decrement the tag by one
var numRows = tag-1;
table.removeRow(tag);
//Set the new tag of the table
table.setTag(numRows.toString());
//Add buttons in previous row
addButtons(app);
}
}
return app;
}
The spreadsheet has two sheets, one is named "LocationCodes". The code refers to that sheet with:
and creates the
LocationSheet
variable as a global variable.There is also another sheet named "LOG". That's where all the data from the input form is going.
You want the code to look through every row in the LOG sheet, and for every row in the LOG sheet that exists, send an email. The email gets looked up from somewhere. The obvious choice would be the "Email Address" in column "F" of the LOG sheet, but I need to know absolutely for sure, because there is another email address in column K.
You need a loop in the code that only loops through the number of rows that you need checked in the LOG sheet. Will the number of rows in the LOG sheet always be the same?
The code is getting each individual email from the sheet, line by line:
That code above, gets an individual cell value. If you want to email all of those emails at once, that requires different code.
You would need to loop through each email with a programming loop. That would be for sending a separate email for each email address. If you want to send one email to lots of email addresses, then you'd need to concatenate them.
There is no loop in the code, or anything that would send multiple emails.