Change tab colour based on text in different cells

Talldrink

New Member
Joined
May 20, 2016
Messages
3
Hi, thanks for taking my question - my first post on the site!

I would like the tab colour of one of my sheets to turn yellow only if either B9 or B11 has the word "NO" in it. Both B9 and B11 have drop down selections for either 'YES' or 'NO' - not sure if that impacts the code???

Thanks a bunch!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi, thanks for taking my question - my first post on the site!

I would like the tab colour of one of my sheets to turn yellow only if either B9 or B11 has the word "NO" in it. Both B9 and B11 have drop down selections for either 'YES' or 'NO' - not sure if that impacts the code???

Thanks a bunch!
Hi TallDrink, welcome to the boards.

To be honest having done some testing when writing this code I am not sure yellow is the best choice as it is difficult to distinguish the yellow from the default colour. That said, the following Worksheet_Change code should do what you need. Right-click on the tab name, select View Code, then paste in the following:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


' If you update B9 or B11 then...
If Target.Address = "$B$9" Or Target.Address = "$B$11" Then
    ' If you select no then...
    If Target.Value = "NO" Then
        ' Change the tab colour to yellow
        ActiveSheet.Tab.ColorIndex = 6
    ' Else if you select yes then...
    Else
        ' If B9 and B11 are BOTH now yes then...
        If Application.WorksheetFunction.CountIf(Range("B9:B11"), "NO") = 0 Then
            ' Reset the tab colour to default
            ActiveSheet.Tab.ColorIndex = xlNone
        End If
    End If
End If


End Sub
 
Upvote 0
Thanks so much, this worked beautifully!!

One question: If I select 'NO' in one of the cells, the tab changes colour as it should. If I change the cell to 'YES', then the tab goes back to the default colour, as it should. However, if I select 'NO' and then delete the cell, the tab remains yellow. Is there a way to get the tab to change colour only when 'NO' is selected (i.e. it won't stay yellow if the cell is deleted and left blank)?

Thanks again!
 
Upvote 0
Thanks so much, this worked beautifully!!

One question: If I select 'NO' in one of the cells, the tab changes colour as it should. If I change the cell to 'YES', then the tab goes back to the default colour, as it should. However, if I select 'NO' and then delete the cell, the tab remains yellow. Is there a way to get the tab to change colour only when 'NO' is selected (i.e. it won't stay yellow if the cell is deleted and left blank)?

Thanks again!
Happy to help.

With regards to your query, maybe something like this perhaps? Changes highlighted in red:

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)


' If you update B9 or B11 then...
If Target.Address = "$B$9" Or Target.Address = "$B$11" Then
    ' If you select No then...
    If Target.Value = "NO" Then
        ' Change the tab colour to yellow
        ActiveSheet.Tab.ColorIndex = 6
    ' Else if you select Yes then...
    Else
        ' If NEITHER B9 or B11 are No then...
        If Target.Value = "" Or Application.WorksheetFunction.CountIf(Range("B9:B11"), "NO") = 0 Then
            ' Reset the tab colour to default
            ActiveSheet.Tab.ColorIndex = xlNone
        End If
    End If
End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,759
Messages
6,126,728
Members
449,332
Latest member
nokoloina

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