Skip to content

Instantly share code, notes, and snippets.

@dDondero
Last active September 28, 2023 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dDondero/762ed91bb862a2b942c6 to your computer and use it in GitHub Desktop.
Save dDondero/762ed91bb862a2b942c6 to your computer and use it in GitHub Desktop.
This Google sheets / Google Apps script searches through all columns in a certain row to find the date matching today, then document automatically scrolls to today's date so you can continue working on the correct spot. Ment to be set up with a trigger On open document. Some other customizing set up here.
function onOpen() { // find where date maches today, then scroll to the end of sheet, then scroll back to matched date
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var values = sheet.getSheetValues(1,1,1,sheet.getMaxColumns());
var objvalues = Transpose(values);
var today = new Date().setHours(0,0,0,0); // change date format to numbers
for(var n=0;n<objvalues.length;++n){ // for each objvalues object run command
var date = new Date(objvalues[n][0]).setHours(0,0,0,0); // adjust format of objvalues to match today format
Logger.log(today+' =? '+date)
if(date==today){
n++
Logger.log('Found match on column: '+n)
sheet.getRange(1, sheet.getLastColumn()).activate();
SpreadsheetApp.flush(); //update sheet
Utilities.sleep(100); //pause 1/2 sec
sheet.getRange(3,n-14,1,14).activate(); // set to (1,n) to only activate today's cell if your dates are in row A
sheet.getRange(4,n).setBackground('red').setFontColor('white'); // OPTIONAL - set red background and white font on today's date
sheet.getRange(4,n-7,1,7).setBackground('#666').setFontColor('white'); // OPTIONAL - reset color on earlier dates
break;
}
}
}
function Transpose(a){ // objectify values - put each cell value in specified row into objects/brackets
return Object.keys(a[0]).map( function (c) { return a.map(function (r) { return r[c];}); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment