Change Tab colour based of multiple cell values

qamex

New Member
Joined
Apr 16, 2018
Messages
5
Hi team,

I've managed to change the Tab colour based of the results of an existing macro in cell "D9"
I also need it to look at a second cell "G31" and if there is an "x" in it. The Tab should turn Blue.
I also want the purple formatting to take priority if they clash.
e.g. If the Macro returns a value that forces the purple colour and there is also an X in "G31" it will ignore the "x" and maintain the purple colour.

I'm not great at writing code but I can read and understand enough to modify what I find online. So please explain the solution as you would a child.

The code I'm currently using is;
Private Sub Worksheet_Change(ByVal Target As Range)
MyVal = Range("D9").Text
With ActiveSheet.Tab
Select Case MyVal
Case "Unsatisfactory Performance"
.ColorIndex = 29
Case "Considerable Improvement Required"
.ColorIndex = 29
Case "Some Improvement Required"
.ColorIndex = 29
Case "Fulfils Expectations"
.ColorIndex = xlColorIndexNone
Case "Exceeds Expectations"
.ColorIndex = xlColorIndexNone
Case "Outstanding Performance"
.ColorIndex = xlColorIndexNone
Case Else
.ColorIndex = xlColorIndexNone
End Select
End With
End Sub


Appreciate the help.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
[COLOR=#008000]    'If the cell that was changed was cell D9 or G31[/COLOR]
    If Target.Address(0, 0) = "D9" Or Target.Address(0, 0) = "G31" Then
        With ActiveSheet.Tab
            Select Case Range("D9").Value
                Case "Unsatisfactory Performance", "Considerable Improvement Required", "Some Improvement Required"
                    .ColorIndex = 29
                Case Else
                    If Range("G31").Value = "x" Then
                        .Color = vbBlue
                    Else
                        .ColorIndex = xlColorIndexNone
                    End If
            End Select
        End With
    End If
End Sub
 
Last edited:
Upvote 0
If the only cases you want to cause a purple tab are the first three in your code, this shorter version should do what you want with respect to the purple taking precedence over blue.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
MyVal = Range("D9").Text
With Me.Tab
Select Case MyVal
    Case "Unsatisfactory Performance"
    .ColorIndex = 29
    Case "Considerable Improvement Required"
    .ColorIndex = 29
    Case "Some Improvement Required"
    .ColorIndex = 29
    Case Else
    If UCase([G31]) = "X" Then
        .Color = vbBlue
    Else
        .ColorIndex = xlColorIndexNone
    End If
End Select
End With
End Sub
 
Upvote 0
JoeMo, works an absolute treat. Champion mate.

Love this site and the community.



If the only cases you want to cause a purple tab are the first three in your code, this shorter version should do what you want with respect to the purple taking precedence over blue.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
MyVal = Range("D9").Text
With Me.Tab
Select Case MyVal
    Case "Unsatisfactory Performance"
    .ColorIndex = 29
    Case "Considerable Improvement Required"
    .ColorIndex = 29
    Case "Some Improvement Required"
    .ColorIndex = 29
    Case Else
    If UCase([G31]) = "X" Then
        .Color = vbBlue
    Else
        .ColorIndex = xlColorIndexNone
    End If
End Select
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top