VBA tab color change to color of cell in range

Angel_Morrefni

New Member
Joined
Feb 2, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello Forum,

I have a workbook with alot of sheets. To easily check if any inspection is due i want my tab color to represent the most critical status to be shown.
I tried piecing together some code but nothing really worked for me.


In my column of inspection due dates i need to search for either red or yellow cells.
If there are any red (or yellow) cells in that column i need the tab color to change to the according color. Red has priority.
The cell color comes from conditional formatting.


Alternatively i considered a separate sheet which shows all the sheet-names in a column.
Each sheet-name should have the according color of the most critical status.

I hope this information is sufficient. :)

Kind Regards
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the forum.
You haven't specified which column you are checking so I assume the range was A1 to A9 just for testing, change this to whatever you want. I assume it is the same ragne on every sheet
VBA Code:
Sub test()
Dim cl As Range
red = 13551615
yellow = 10284031

For i = 1 To Worksheets.Count
    With Worksheets(i)
    tred = False
    tyellow = False
    For Each cl In .Range("a1:a9")
    tt = cl.DisplayFormat.Interior.Color
    If tt = red Then
     tred = True
     Exit For
    End If
    If tt = yellow Then
     tyellow = True
    End If
    
    Next cl
    
    If tred Then
     .Tab.Color = vbRed
    Else
     If tyellow Then
     .Tab.Color = vbYellow
     Else
     .Tab.Color = vbWhite
     End If
    End If
    End With
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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