0
votes

Any ideas as to how I can implement a timer into my google spreadsheet?

I'd like there to be a digital timer with a start and reset button. The purpose of the reset button would be to set the clock to 2 minutes.

I am operating an NHL Fantasy draft with Google Sheets and would like there to be a clock at the top of the spreadsheet, with the draft pick table below it.

1

1 Answers

1
votes

The below will create a timer for 2 minutes:

function timer() {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('Sheet'); // Change to your sheet name
  var m = 2; // How many minutes it will run for
  var s = 0;
  for (var i = -1; i < s; i--) {
    if(s == 0 && m == 0) {
      break;
    }
    else if(s == 0) {
      s=59;
      m--;
    }
    else {
      s--;
    }
    SpreadsheetApp.flush();
    Utilities.sleep(1000);
    sh.getRange('A1').setValue(m+':'+s); // Change the cell to where you want timer to be displayed
  }
}

You can then run this buy inserting a button. Go to Insert > Drawing > then create a shape. Once inserted, click on the three dots in top right corner > Assign script > Enter timer

It will reset to 2 minutes every time you click the button.