Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2009
    Posts
    4

    Question Unanswered: Tab Color If Statement

    Does anyone know how to write the code to change the tab color of a worksheet if a True False Statement within that worksheet is False? I have Microsoft 2007. I would like the tab color to turn red if cell S21 is False and Green if cell S21 is True. If you need to know any other information let me know. Thanks!

  2. #2
    Join Date
    May 2009
    Posts
    258
    Try this:
    Code:
    Dim rngBool As Range, iColor As Integer
    Set rngBool = ActiveSheet.Range("S21")
    iColor = xlColorIndexNone
    If rngBool.Value = "True" Then
        iColor = 4
    ElseIf rngBool.Value = "False" Then
        iColor = 3
    End If
    ActiveSheet.Tab.ColorIndex = iColor
    Regards,

    Ax

  3. #3
    Join Date
    Sep 2009
    Posts
    4
    Do I need to do edit any of this or should it just work if i cut and paste it into the view code when I right click the tab I want it for because I did that and it didn't work. Does the tab name need to be included? If so the tab name is "Program Analysis"

  4. #4
    Join Date
    May 2009
    Posts
    258
    You'll have to put it in a sub.
    Last edited by Ax238; 09-16-09 at 17:49.

  5. #5
    Join Date
    Sep 2009
    Posts
    4
    Okay. I am not familiar with subs so what exactly needs to be put into the code? Thanks Ax238

  6. #6
    Join Date
    May 2009
    Posts
    258
    I posted a link in my last response, that should give you all the information you need. It's a pretty good tutorial. I pointed you directly where you find Sub and Function declarations, but it would behoove you to read through the whole thing... especially if you want to learn how to program macros in Excel.

    Ax

  7. #7
    Join Date
    Oct 2009
    Posts
    6
    This may sound simple, but have you tried theConditional Formating ->Highlights Cell Rules-> Text Containing..> write in TRUE and condition the cell fill as green...but then, this is simple, not sure whether I understood your goal.

  8. #8
    Join Date
    Sep 2009
    Posts
    4
    I believe that is only for changing a cell color based on the formula. The goal is to have the conditional formating of the tab itself change colors depending on an if statement within that tab which is based on several other tabs within the workbook. Hopefully this helps.

  9. #9
    Join Date
    Oct 2009
    Posts
    6
    Ax238 is your guy then, soory i didnt read tour definiton properly!

Posting Permissions

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