I am trying to create a number of rows in a Sheet after the last row having the specified date (F5 cell value) and based on user inputs in H5, I5, J5, K5 cells (some of them may be blank). User inputs are taken in the Dashboard Sheet, which is attached herewith this post. And the sheet where the data will be stored is specified in F5 having following format:
Date Student ID Umail Latitude Longitude Subject
2020-08-20 (G5) 1902011 (H5) 1902011@icte.bdu.ac.bd (H5 + K3) - - ICTE4115 (F5)
2020-08-20 (G5) 1902015 (I5) 1902015@icte.bdu.ac.bd (I5 + K3) - - ICTE4115 (F5)
2020-08-20 (G5) 1902024 (J5) 1902024@icte.bdu.ac.bd (J5 + K3) - - ICTE4115 (F5)
2020-08-20 (G5) 1902036 (K5) 1902036@icte.bdu.ac.bd (K5 + K3) - - ICTE4115 (F5)
My codes are: When values in K6 cell selected, the function onePeriod() will be called.
function onePeriod(){
// For a single Period Class
var spreadsheet = SpreadsheetApp.getActive();
var dashboard = spreadsheet.getSheetByName("Dashboard");
var sheetName = dashboard.getRange("F5").getValue();
var sheet = spreadsheet.getSheetByName(sheetName);
var umailPattern = dashboard.getRange("K3").getValue();
//Locate the lastrow of the specified date
var mDate = dashboard.getRange("G5").getDisplayValue();
var startRow = 2;
var dateColumn = sheet.getRange(startRow,1,sheet.getLastRow(), 1);
var dates = dateColumn.getDisplayValues().flat();
var lastRow = dates.lastIndexOf(mDate)+startRow;
//Dashboard is the place for user input where in H5, I5, J5, K5 cell student IDs are entered.
var sheet1 = spreadsheet.getSheetByName('Dashboard');
//Need to bring all student IDss from those cells of Dashboard to students array.
var data = sheet1.getLastColumn();
var students = [];
var students = sheet1.getRange(5, 8, 1, data).getValues();
var ssId = SpreadsheetApp.getActiveSpreadsheet().getId();
var ss = SpreadsheetApp.openById(ssId);
for (var i=1; i<=students.length; i++){ // you are looping columwise through cells H5, I5, J5, K5 in row 5.
if (students[i+7][0] !== ''){
sheet.insertRowAfter(lastRow);
range1 = sheet.getRange(lastRow+1, 1, 1, 6);
range1.getCell(lastRow+1,1).setValue(dates);
range1.getCell(lastRow+1,2).setValue(students[i+7][0].toString());
range1.getCell(lastRow+1,3).setValue(students[i+7][0].toString() + umailPattern);
range1.getCell(lastRow+1,4).setValue('');
range1.getCell(lastRow+1,5).setValue('');
range1.getCell(lastRow+1,6).setValue(sheetName);
}
}
}
(G5), (H5), (H5 + K3)
. So in order to correctly understand about your question, can I ask you about the detail of input and output you expect? And also, can I ask you about the detail of current issue of your script? – Tanaikethe code does not insert the inputs in the output sheet, can't find where is the error.
. But, unfortunately, I cannot still understand about your goal. This is due to my poor skill. I deeply apologize for this. In order to correctly understand about your goal, can you provide the sample input and output you expect? Unfortunately, I cannot understand about your goal from your question. I apologize for this, again. – Tanaike