Change the tab colour based on multiple date enties

cwcwcw

New Member
Joined
May 7, 2019
Messages
5
Hi, I have a worksheet that has 20 different expiry dates, they are individual cells, not in a range. If any one of these cells become expired I would like the tab to be highlighted, I am a complete beginner at this so sorry if I've got any definitions wrong and thanks.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
See if this Worksheet_Calculate event handler works for you. The code must be put in the sheet module, so to insert the code, right-click the sheet's tab and click View Code, and paste the code.

Code:
Private Sub Worksheet_Calculate()

    Dim cell As Variant, expired As Boolean
    
    expired = False
    For Each cell In Split("A5,A10,A15,A20,A25,A30", ",")
        If Range(cell).Value <= Date Then expired = True
    Next

    If expired Then
        Me.Tab.Color = vbRed
    Else
        Me.Tab.Color = vbWhite
    End If
    
End Sub
Change the cell addresses shown to suit. The sheet tab changes to red when any of the dates in those cells is less than or equal to today's date.
 
Upvote 0
Thanks John, I think I can see how that works, I'm still working on my spread sheet so not quite ready to input this yet, I'll be sure to let you know how it goes tho. thank you, chris
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,208
Members
452,618
Latest member
Tam84

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