Focus Sheet on Cell with Date

Have to share a quick snippet I wrote today after getting frustrated scrolling all over spreadsheets looking for today's date. Maybe this will be helpful to someone else

#googleappsscript #googlesheets

function focus() 
  const sheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME);
  const range = sheet.getDataRange();
  const vals = range.getValues();
  const today = new Date();
  
  for(let y = 0; y < vals.length; y++) {
    const x = vals[y].findIndex(cell => cell instanceof Date && cell.toDateString() === today.toDateString());


    if(x > -1) {
      return sheet.getRange(y + 1, x + 1).activate();
    }
  }
}{        

要查看或添加评论,请登录

社区洞察

其他会员也浏览了