I have a spreadsheet in which we put out planning. From column B till the last possible column there are dates on row A2. I tried to write a function that places your cursor on this cell. But I'm a little stuck and my knowledge of javascript is limited.
function onOpen() {
getTodayRow();
};
function getTodayRow(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('2014a');
var rowContent = sheet.getRange('B:A2').getValues();
var today = new Date().getDate();
var val = 1;
for(var n in rowContent)
{
if (new Date(rowContent[n][0]).getDate() == today)
{
val=Number(n)+1;break
}
}
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(val);
// return val;
// the +1 above is because arrays count from 0 and rows count from 1. (Number() is to avoid having 13+1=131 which is the default behavior unfortunately)
sheet.setActiveCell(sheet.getRange(2, val)); //activate on right date
}
Is there anyone who can tell me where I went wrong?