I am trying to change the tab color based on a cell value on an individual sheet. I have multiple tabs. The cell value that will determine whether or not it gets a color is a cell containing a date.
This is what I have- I can't get it to work. Any suggestions?
function onEdit(e) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var first = ss.getSheetByName("3005"); var second = ss.getSheetByName("3006"); var third = ss.getSheetByName("3007"); var fourth = ss.getSheetByName("3008"); var cell1 = first.getRange("c26"); var cell2 = second.getRange("c24"); var cell3 = third.getRange("c24"); var cell4 = fourth.getRange("c24"); var cellContent1 = cell1.getValue(); if (cellContent1 == "date") { first.setTabColor("#66FF00"); } if (cellContent1 == 0) { first.setTabColor(null);} var cellContent2 = cell2.getValue(); if (cellContent2 == "date") { second.setTabColor("#66FF00"); } if (cellContent2 == 0) { second.setTabColor(null);} var cellContent3 = cell3.getValue(); if (cellContent3 == "date") { third.setTabColor("#66FF00"); } if (cellContent3 == 0) { third.setTabColor(null);}var cellContent4 = cell4.getValue(); if (cellContent4 == "date") { fourth.setTabColor("#66FF00"); } if (cellContent4 == 0) { fourth.setTabColor(null);}}If I tell it to change color based on a number it works fine - i.e.
function onEdit(e) { var ss = SpreadsheetApp.getActiveSpreadsheet();var first = ss.getSheetByName("3005"); var cell1 = first.getRange("i20"); var cellContent1 = cell1.getValue(); if (cellContent1 == 1) { first.setTabColor("#66FF00"); } if (cellContent1 == 0) { first.setTabColor(null);}}