0
votes

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

1
So cell A4 is every tab has a date in it and you wish to change the color of the tab if the date in A4 is older that todays date. Is that correct? If so what what colors do you want? Are there any tabs that you wish to exclude from this operation? - Cooper

1 Answers

2
votes
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);
    }
  })
}