Conditional Format multiple worksheet tabs color based on a date in each sheet

FadeToOrange

New Member
Joined
Feb 26, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

I'm building a workbook to track and monitor the recruitment plans for several job positions. The workbook has 2 informational sheets 8 sheets for the roles needing to be filled (1 sheet for each of the 8 jobs). In cell A10 of each job sheet is the recruitment start date. I'm trying to create a way to change the color of the job tab to green when that date is within 1 week or less of the date in cell A10. I've poked around on other posts that were similar and attempted the VBA scripts suggested - tweaking to my specs - and have the below script which works if I go into each tab and update the date, but I'd like it to update all the tabs all the time based on the current date. The file usually sits open on my computer and I'm not always updating the individual sheets, but want to be able to see in real time which sheets are "active" (in the recruitment process period) or not.

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

If Sh.Range("A10").Value - 7 >= Now() Then
Sh.Tab.ColorIndex = -4142 ' No Color
Else
Sh.Tab.ColorIndex = 10 ' Green
End If
End Sub



Appreciate the help and input.
Mike
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
What's the names of the 2 "informational sheets"? I think this would be best handled with a workbook_open event, but we'd need to know the names of those two sheets to exclude them from the code execution.
 
Upvote 0
What's the names of the 2 "informational sheets"? I think this would be best handled with a workbook_open event, but we'd need to know the names of those two sheets to exclude them from the code execution.
"People Plan" and "Resources"
 
Upvote 0
Try the following Workbook Open event code on a copy of your file:

VBA Code:
Option Explicit
Private Sub Workbook_Open()
    Dim ws As Worksheet, start
    For Each ws In ThisWorkbook.Worksheets
        Select Case ws.Name
            Case "People Plan", "Resources"
            Case Else
                start = ws.Range("A10")
                If IsDate(start) Then
                    If Date >= (start - 7) Then
                        ws.Tab.ColorIndex = 10
                    Else
                        ws.Tab.ColorIndex = xlColorIndexNone
                    End If
                Else
                    ws.Tab.ColorIndex = xlColorIndexNone
                End If
        End Select
    Next ws
End Sub

If you're not familiar with adding Workbook event code, this video may be useful:
 
Upvote 0
Ok so one more question, is it possible to also trigger when something is changed on "DASHBOARD"? So right now it will only trigger and change color of tab to green if I close and reopen the file, but I also need it to change if I make changes to the sheets. It is set up so you input the recruitment plan start dates for each of the jobs on the Dashboard sheet and then it updates the corresponding job sheet with the info. So if I could have it trigger if there is any change on "Dashboard" sheet and then it runs the event again on each ws checking the date to see if its in the parameter to change the tab color to green. Hope that makes sense.
 
Upvote 0
So I'm guessing that "DASHBOARD" is another sheet not previously mentioned? I guess you want it excluded from the initial workbook open event code as well? If I'm guessing correctly, then add the following code to the worksheet event code area for the sheet "DASHBOARD":

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Dim ws As Worksheet, start
        For Each ws In ThisWorkbook.Worksheets
            Select Case ws.Name
                Case "People Plan", "Resources", "DASHBOARD"
                Case Else
                    start = ws.Range("A10")
                    If IsDate(start) Then
                        If Date >= (start - 7) Then
                            ws.Tab.ColorIndex = 10
                        Else
                            ws.Tab.ColorIndex = xlColorIndexNone
                        End If
                    Else
                        ws.Tab.ColorIndex = xlColorIndexNone
                    End If
            End Select
        Next ws
    Application.EnableEvents = True
End Sub

And add "DASHBOARD" to the relevant workbook open event code line, like this:

Rich (BB code):
Case "People Plan", "Resources", "DASHBOARD"
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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