I am trying to create a function in Google Sheets that will jump to the cell containing today's date.
The following function works if the dates are in one column and formatted as mm/dd/yyyy.
function gotoToday() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getRange("G:G");
var values = range.getValues();
var day = 24*3600*1000;
var today = parseInt((new Date().setHours(0,0,0,0))/day);
var ssdate;
for (var i=0; i<values.length; i++) {
try {
ssdate = values[i][0].getTime()/day;
}
catch(e) {
}
if (ssdate && Math.floor(ssdate) == today) {
sheet.setActiveRange(range.offset(i,0,1,1));
break;
} }
}
However, the cells containing the dates in my sheet are populated as "=A1+1" etc, and spread across columns as follows:
How can the function above be edited so it can find and match today's date?
Thank you
UPDATE: I have managed to make the function work across multiple columns. Now I just need to know how to read the date when the cell is populated as =A1+1, A2+1 etc
Two things:
var range = sheet.getRange("G:G");
var range = sheet.getDataRange();
ssdate = values[i][0].getTime()/day;
), but you'll need two nestedfor
loops to loop through both rows and columns:ssdate = values[i][j].getTime()/day;
getTime()
cannot be applied to it.Format ->Number -> Date
References: