Changing Tab Color based on certain cell value using VBA

sprimax

New Member
Joined
Oct 3, 2008
Messages
41
Folks,

I have 5 sheets, name 1,2,3,4 and Summary what I want is :
if cell value in B6 (progress) is 0%, then tab color changing to Red
if cell value in B6 (progress) is greater than 0 but less than 100%, tab color change to Green. Else is Black.

That should happen only in sheets 1,2,3,4 but not for Summary.

Is there any code to do that ?

I tried to put the code in ThisWorkbook, and it won't work :
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B6").Value = 0 Then
ActiveWorkbook.Sheets.Tab.Color = 255
ElseIf Range("B6").Value < 1 Then
ActiveWorkbook.Sheets.Tab.Color = 5287936
ElseIf Range("B6").Value = 1 Then
ActiveWorkbook.Sheets.Tab.Color = 0
Else
ActiveWorkbook.Sheets("test").Tab.ColorIndex = -4142
End If
End Sub

Please help me, thank you
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

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