What I'm trying to do is within one spreadsheet, look at sheet "Source", if a cell in column B contains today's date, then copy cells between A:B for that cell and paste onto next empty row in sheet "Destination".
Repeat for all cells containing today's date.
This works if I'm looking for a text but essentially I'm trying to make this run automatically everyday when the date changes and I can't get the date function to work properly.
Essentially at the turn of each day it would copy today's data from another automated sheet, and paste it in the next row down from yesterday's data in another sheet.
I'm quite new to all of this and any help would be greatly appreciated.
function copy_test() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Source"); //Source sheet
var ds = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Destination"); //Destination sheet
var testrange = ss.getRange('B:B'); //Column to check for today's date
var testvalue = (testrange.getValues()); //What value to check
var today = Utilities.formatDate(new Date(), 'GMT-0', 'dd/MM/yyyy');
var data = [];
var j = [];
//Condition to check in B:B, if true, copy the same row to data array
for (i=0;i<testvalue.length;i++) {
if (testvalue[i] == today) {
data.push.apply(data,ss.getRange(i+1,1,1,3).getValues());
//Copy matched ROW numbers to j
j.push(i);
}
}
//Copy data array to destination sheet
ds.getRange(ds.getLastRow()+1,1,data.length,data[0].length).setValues(data);
}
The error I get is:
TypeError: Cannot read property "length" from undefined. (line 20, file "First Test")
today
in your code included hours, minutes, seconds and milliseconds and it's doubtful that any of your dated matched exactly. – Cooper