Faisal
Faisal

Reputation: 441

Google sheet change tab color based on date comparing

I have a google sheet that contains dates, I want to change all the tab color if the today date higher than the cell date

I have like 30 tab and each one has the same cell but different date

the cell position: A4

Upvotes: 0

Views: 223

Answers (1)

Cooper
Cooper

Reputation: 64032

function changeColorIfA4IsEarlierThanToday() {
  var ss=SpreadsheetApp.getActive();
  var shts=ss.getSheets();
  var today=new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()).valueOf();
  shts.forEach(function(sh){
    var val=sh.getRange('A4').getValue();
    if(new Date(val).valueOf()<today) {
      sh.setTabColor('#ffff00');
    }else{
      sh.setTabColor(null);
    }
  })
}

Upvotes: 2

Related Questions