简体   繁体   中英

Auto Scroll through the spreadsheet to display "today's date" using google app scripts with the full date name

Hi I'm needing help in auto scrolling using app script but using the date in the full format "Wednesday 19 October 2022". I have used data validation and the selected date for Criteria and change the format to a custom display of [DAY(WEDNESDAY),DAY(19),MONTH(October),YEAR(2022)]

the sheet has about 4800 rows and starts with "Tuesday 11 January 2022" and goes down all the way to "Friday 23 December 2022 " so we care currently at row 3000+/- and is becoming a pain to scroll down every time you open the sheet

I have though about hiding the used sheets but still needing to search and look up that data so then I have to hid and un hide the rows

Here is an example of setting the active cell onOpen(). This example has dates in column A. If you wanted it to also work if you change the sheet you could use onSelectionChange(). Notice I remove the time of day from all dates to compare them.

function onOpen(e) {
  let spread = SpreadsheetApp.getActiveSpreadsheet();
  let sheet = spread.getActiveSheet();
  let values = sheet.getRange(1,1,sheet.getLastRow(),1).getValues();
  let today = new Date();
  today = new Date(today.getFullYear(),today.getMonth(),today.getDate());
  values.some( (row,index) => {
      let cell = row[0];
      cell = new Date(cell.getFullYear(),cell.getMonth(),cell.getDate());
      if( cell.valueOf() ==  today.valueOf() ) {
        sheet.setCurrentCell(sheet.getRange("A"+(index+1)));
        return true;
      }
      return false;
    }
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM