Results 1 to 9 of 9

Thread: Change Tab Color base on value of cell % Change

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0

    Change Tab Color base on value of cell % Change

    I have code like this, but it does not change to the right color,

    Code:
        If Sheets("Sheet3").Range("S45").Value > "0.00" Then
           Sheets("Sheet3").Tab.ColorIndex = 5                 '-----Change Tab Color (Blue)
           Sheets("Sheet1").Tab.ColorIndex = 5                 '-----Change Tab Color (Blue)        > 0.00%
           Sheets("Sheet2").Tab.ColorIndex = 5                 '-----Change Tab Color (Blue)
        End If
        If Sheets("Sheet3").Range("S45").Value > "3.00%" Then
           Sheets("Sheet3").Tab.ColorIndex = 4                 '-----Change Tab Color (Green)
           Sheets("Sheet1").Tab.ColorIndex = 4                 '-----Change Tab Color (Green)       > 3.00%
           Sheets("Sheet2").Tab.ColorIndex = 4                 '-----Change Tab Color (Green)
        End If
        If Sheets("Sheet3").Range("S45").Value < "0.00" Then
           Sheets("Sheet3").Tab.ColorIndex = 46                '-----Change Tab Color (Orange)
           Sheets("Sheet1").Tab.ColorIndex = 46                '-----Change Tab Color (Orange)      < 0.00%
           Sheets("Sheet2").Tab.ColorIndex = 46                '-----Change Tab Color (Orange)
        End If
        If Sheets("Sheet3").Range("S45").Value < "-3.00%" Then
           Sheets("Sheet3").Tab.ColorIndex = 3                 '-----Change Tab Color (Red)
           Sheets("Sheet1").Tab.ColorIndex = 3                 '-----Change Tab Color (Red)         < -3.00%
           Sheets("Sheet2").Tab.ColorIndex = 3                 '-----Change Tab Color (Red)
        End If
        
    End Sub
    Last edited by mrprofit; 04-12-2014 at 02:05 AM.

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    try

    Code:
    Option Explicit
    
    Sub kTest()
        
        Dim tColor      As Long
        
        tColor = Evaluate("=LOOKUP('Sheet3'!S45,{-9.99,3;-0.03,46;0,5;0.03,4})")
        
        Sheets("Sheet3").Tab.ColorIndex = tColor
        Sheets("Sheet1").Tab.ColorIndex = tColor
        Sheets("Sheet2").Tab.ColorIndex = tColor
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0
    Works, Thank you

    now i have another question, possible to use a cell R1 to replace the 0.03 in the code? R1 = 3%, so S45 < R1 then change Tabcolor to Red etc,

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Are you always compare S45 to R1 or different cells for different values ?
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0
    I will compare it to R1 always, and possible to add another R2 =10%, then Change to Tabcolor to another color

    Thank you for your help

  6. #6
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    You mean like this ?

    Code:
    Option Explicit
    
    Sub kTest()
        
        Dim S45_Value   As Double
        Dim R1_Value    As Double
        
        S45_Value = Sheets("Sheet3").Range("S45").Value
        R1_Value = Sheets("Sheet3").Range("R1").Value
        
        Select Case True
            Case S45_Value > R1_Value
                If S45_Value > 0.03 Then
                    Sheets("Sheet3").Tab.ColorIndex = 4
                    Sheets("Sheet2").Tab.ColorIndex = 4
                    Sheets("Sheet1").Tab.ColorIndex = 4
                ElseIf S45_Value > 0 Then
                    Sheets("Sheet3").Tab.ColorIndex = 5
                    Sheets("Sheet2").Tab.ColorIndex = 5
                    Sheets("Sheet1").Tab.ColorIndex = 5
                End If
            Case S45_Value < R1_Value
                If S45_Value < 0 Then
                    Sheets("Sheet3").Tab.ColorIndex = 46
                    Sheets("Sheet2").Tab.ColorIndex = 46
                    Sheets("Sheet1").Tab.ColorIndex = 46
                ElseIf S45_Value < -0.03 Then
                    Sheets("Sheet3").Tab.ColorIndex = 3
                    Sheets("Sheet2").Tab.ColorIndex = 3
                    Sheets("Sheet1").Tab.ColorIndex = 3
                End If
        End Select
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  7. #7
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0
    instead of using all the sheets name, what code to just choose all sheets

    Code:
       Sheets("Sheet3").Tab.ColorIndex = 46
       Sheets("Sheet2").Tab.ColorIndex = 46
       Sheets("Sheet1").Tab.ColorIndex = 46
    it this the code ?
    Code:
    worksheets.Tab.ColorIndex = 46

  8. #8
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by mrprofit View Post
    instead of using all the sheets name, what code to just choose all sheets

    Code:
       Sheets("Sheet3").Tab.ColorIndex = 46
       Sheets("Sheet2").Tab.ColorIndex = 46
       Sheets("Sheet1").Tab.ColorIndex = 46
    it this the code ?
    Code:
    worksheets.Tab.ColorIndex = 46
    Try it this way...
    Code:
    Dim WS As WorkSheet
    ....
    ....
    For Each WS in Worksheets
      WS.Tab.ColorIndex = 46
    Next

  9. #9
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0
    Thank you Rick

Similar Threads

  1. Change Shape Color on MouseOver
    By Ashu2021 in forum Excel Help
    Replies: 1
    Last Post: 01-31-2014, 01:11 PM
  2. Replies: 14
    Last Post: 10-23-2013, 01:24 PM
  3. Replies: 8
    Last Post: 04-16-2013, 02:04 PM
  4. Change Display Range Based On Change of Dropdown Values
    By rich_cirillo in forum Excel Help
    Replies: 2
    Last Post: 03-29-2013, 04:58 AM
  5. Replies: 1
    Last Post: 08-21-2012, 07:36 PM

Posting Permissions

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