+ Reply to Thread
Results 1 to 4 of 4

Google sheets- change color of tab based on cell value

  1. #1
    Registered User
    Join Date
    04-22-2022
    Location
    United States
    MS-Off Ver
    32 bit Office 10
    Posts
    12

    Google sheets- change color of tab based on cell value

    Hi.

    I am trying to change the color of a tab based on a cell value, which is a date. There are multiple tabs. This is what I have written:

    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 fifth = ss.getSheetByName ("3009");
    var cell1 = first.getRange("c26");
    var cell2 = second.getRange("c24");
    var cell3 = third.getRange("c24");
    var cell4 = fourth.getRange("c24");
    var cell5 = fifth.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);}
    var cellContent5 = cell1.getValue();
    if (cellContent5 == 'DATE') {
    fifth.setTabColor("#66FF00");
    }
    if (cellContent5 == 0) {
    fifth.setTabColor(null);}}

    The script excutes and completes- but no changes to the color on the tab.

    If I base the color change on a number, for example it works perfectly 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);}

    https://docs.google.com/spreadsheets...it?usp=sharing

    What am I missing?

    Thank you for your time.
    Last edited by VikkiD; 01-18-2024 at 11:38 AM.

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Google sheets- change color of tab based on cell value

    VikkiD

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. No help to be offered until you provide a link or, for members with fewer than 10 posts, a comment telling us where else you have posted this query.)

    Since you did not have 10 posts at the time of posting your question I'll post the link for you this time.

    https://webapps.stackexchange.com/qu...-google-sheets
    Last edited by FlameRetired; 01-18-2024 at 03:14 PM.
    Dave

  3. #3
    Registered User
    Join Date
    04-22-2022
    Location
    United States
    MS-Off Ver
    32 bit Office 10
    Posts
    12

    Re: Google sheets- change color of tab based on cell value

    Oh I am so sorry. I did not read the rules. I will read them and comply.

    Again, my apologies.

    Thank you.

  4. #4
    Registered User
    Join Date
    04-22-2022
    Location
    United States
    MS-Off Ver
    32 bit Office 10
    Posts
    12

    Re: Google sheets- change color of tab based on cell value


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Google sheets - change cell color based on days past date in another cell
    By Coffey80 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 03-10-2021, 03:20 PM
  2. Google Sheets: Cell changes color based on current time
    By TimRodriguez in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 04-15-2020, 06:48 AM
  3. Google Sheets: Background cell color changes
    By jher001 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 04-07-2018, 10:42 AM
  4. Replies: 0
    Last Post: 10-31-2017, 12:56 PM
  5. Change cell format (cell color+font color) based on color of another cell
    By Dedaluss in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2017, 03:27 AM
  6. email row contents based on cell values (google sheets populated by google forms)
    By reedg in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 01-13-2016, 02:55 PM
  7. Replies: 13
    Last Post: 07-09-2014, 04:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1