+ Reply to Thread
Results 1 to 13 of 13

Changing tab color based on cell value

  1. #1
    Registered User
    Join Date
    03-06-2014
    Location
    Houston, TX
    MS-Off Ver
    Office 2010
    Posts
    4

    Changing tab color based on cell value

    Hi all,

    I am using Excel 2010 and trying to change/edit the color of the tabs in my workbook to turn green or red based on a y or n placed in a cell (the same cell on each tab). I have tried variations on several themes others have asked about as well for Excel 2007 and attempted to adapt them to fit my situation but none seem to work. Here's what I was starting with:

    Private Sub Worksheet_Change(ByVal Target As Range)

    Select Case Range("A1").Value
    Case Is < 2.5
    Sheet1.Tab.Color = vbRed

    Case Is > 2. 5, Is < 4
    Sheet1.Tab.Color = vbGreen
    End Select

    End Sub

    The cell I'm using is F2 and my cell value is simply y or n. Can someone assist me in finding a solution to this? I realize the example above references numeric values and greater than/less than options, but I'm not sure how to correct this for my need.

    Thanks so much in advance!
    Tim

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Changing tab color based on cell value

    Try:
    Please Login or Register  to view this content.
    Edit: If you want this to apply to ALL worksheets in the workbook, without having to copy the code into every worksheet module, then put this in the Workbook module:
    Please Login or Register  to view this content.
    Last edited by Olly; 03-06-2014 at 06:57 PM.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Changing tab color based on cell value

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    03-06-2014
    Location
    Houston, TX
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: Changing tab color based on cell value

    Olly,

    I tried your first option. I copied the code and then I went to my tab, right clicked and chose View Code. I pasted the code in and then closed the window. Saved my spreadsheet and then entered a value of 'y' (minus the quotes) in the cell F2 and nothing happened. Did I do this wrong?

    When I use the code to affect the whole workbook, it works just fine. Any idea on what I'm doing wrong when I try to apply only to each worksheet in the workbook?
    Last edited by taab0412; 03-06-2014 at 07:02 PM.

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Changing tab color based on cell value

    My apologies - I edited shortly after posting, to include a UCase function, which will accept either "y" or "Y". I should have made my edit clear. Thanks to TMS for prompting me to include that bit!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Changing tab color based on cell value

    I think the comparison is case sensitive.

    Please Login or Register  to view this content.

    Regards, TMS

  7. #7
    Registered User
    Join Date
    03-06-2014
    Location
    Houston, TX
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: Changing tab color based on cell value

    So TMS,

    Your submission is for each worksheet, correct?


    TMS/Olly,
    Is it possible to also edit/affect the shade of green or red? I'm trying to match the color I chose from the palate for a given cell where I signify Y or N.

    Again, thank you...
    Tim
    Last edited by taab0412; 03-06-2014 at 07:15 PM.

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Changing tab color based on cell value

    Yes, replace vbRed with RGB(255,0,0) - tweak RGB values to suit.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Changing tab color based on cell value

    The code would work for any worksheet, as would Olly's, if you copy it to the class module for each sheet where you want it to be effective.

    Alternatively, you could put the following slightly modified code into the Workbook Class Module and it will work for EVERY sheet (as coded):

    Please Login or Register  to view this content.

    Regards, TMS

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Changing tab color based on cell value

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  11. #11
    Registered User
    Join Date
    03-06-2014
    Location
    Houston, TX
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: Changing tab color based on cell value

    Thank you guys SO MUCH! Really appreciate your help. This completely answered my questions.

    Tim

  12. #12
    Registered User
    Join Date
    12-20-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Changing tab color based on cell value

    Hey i could use that stuff but with some other options.
    is it possibel to look over 3 options..

    option 1 if cell value is higher than 8 then (Gold color if possibel)
    option 2 if cell value is 8 then Silver (color if possibel)
    option 3 if cell value is Under 8 then (Bronze If posibel)

    And if nothing in cell then no Tab color .

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Changing tab color based on cell value

    @henrik2: welcome to the forum.


    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

+ 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. changing the color of a cell based on content
    By trisham in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-26-2013, 04:26 PM
  2. [SOLVED] Changing fill color of shapes based on changing cell value
    By Stefan1983 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2012, 10:33 AM
  3. Changing tab color based on cell value
    By PrizeGotti in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-22-2012, 07:29 AM
  4. Changing cell color based on value
    By smraines in forum Excel General
    Replies: 6
    Last Post: 12-30-2009, 07:39 PM
  5. changing cell color based on changing values
    By tvonbehren in forum Excel General
    Replies: 2
    Last Post: 09-16-2009, 12:33 PM

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