I have been trying to copy the value in A9 into the cell in column D, when the current time (now
or time.new
) corresponds to the time specified in the same row in column C.
I managed to get a script that pulls the value D1 once in an hour into the last cell in column D, which would be perfectly fine if the "time-driven" trigger would not pick a random time in the hour. It needs to be exactly 2 minutes past every full hour (+/- 30 seconds). So I thought to make the script run every minute and paste the value in a cell if the time in colum C is within 1h2m30s and 1h1m30s before the present time... But with my script there seems to be an error.
Please find the test document here, where the function is currently being executed once every hour.
The Apps Script that runs at a random time every hour is as follows (currently running):
function myFunction() {
var ss= SpreadsheetApp.getActiveSpreadsheet();
var sheet= ss.getSheetByName('FACTS & PREDICTIONS');
var Direction=SpreadsheetApp.Direction;
let aLast =sheet.getRange("D"+(sheet.getLastRow()+1)).getNextDataCell(Direction.UP).getRow();
let val= sheet.getRange('A9').getDisplayValue();
sheet.getRange(`D${aLast+1}`).setValue(val);
}
The new script, that I have been trying to make is as follows:
function myFunction() {
var ss= SpreadsheetApp.getActiveSpreadsheet();
var sheet= ss.getSheetByName('Admin Panel');
var Direction=SpreadsheetApp.Direction;
if(e.source.getActiveSheet().getName()=="FACTS & PREDICTIONS") {
if(col == 4 && cell.offset(0,-1).getValue() > new Date()-TIME(1,2,30) && col == 4 && cell.offset(0,-1).getValue() < new Date()-TIME(1,1,30)){
let val= sheet.getRange('A9').getDisplayValue();
e.source.getActiveSheet().getRange(row,4).setValue(val);
}
}
}
The above script is actually patched together because I have no clue of Apps Scrips. I have no idea what is wrong with the code or what I need to change.
Edit: Just fount this, where you can make a Trigger locked to a specific minute, BUT it has +/- 15 minutes deviation. Useless...