VBA code for changing tab color based on cell values

youngguy

New Member
Joined
Mar 24, 2011
Messages
4
I need to change all tab colors to correspond with the max value in a range of cells (I10:I30) of that tab. If the max value is less than 5 the tab needs to be green. Between 6-12, yellow. Greater than 12, red. Any help would be greatly appreciated
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try this

Code:
Sub TabColor()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    With ws
        Select Case WorksheetFunction.Max(.Range("I10:I30"))
            Case Is < 5: .Tab.ColorIndex = 4
            Case 6 To 12: .Tab.ColorIndex = 6
            Case Else: .Tab.ColorIndex = 3
        End Select
    End With
Next ws
End Sub
 
Upvote 0
New question-In my excel workbook I have an intro sheet with hyperlinks to each following sheet. Is there a way I can make each cell with the sheets hyperlink the same color as that sheets tab? Example: Intro sheet cell A10 has the hyperlink to sheet 3. Sheet 3's tab color is green. How can I make A10's color green as well? Is there a way to have one code for a range of cells or do I need a code for each cell and corresponding sheet?
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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