VB Code needed for Tab Color

rmarquis

New Member
Joined
Nov 16, 2018
Messages
2
Hi all,

Im not going to pretend that I know VB code but what I am trying to do is take a column of dates E3:E8 and have then turn the tab color yellow if its within a week of the date. So basically if my sheet "test" has a due date thats 3 days from now the tab color will turn yellow to make users aware we have a completion date thats almost here. If there is nothing within a week then it will just be no color.

Thanks so much for the help!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I do not understand how "within a week" and "3 days from now" are the same thing :confused:
But here is something you can tweak to match your required condition (looks for a date in next 7 days)
Code:
Sub ColorTab()

Dim cel As Range, rng As Range
Set rng = Sheets("Test").Range("E3:E8")

For Each cel In rng
    If cel >= Date And cel - Date < 7 Then
        Sheets("Test").Tab.ColorIndex = 6
        Exit Sub
    End If
Next
Sheets("Test").Tab.ColorIndex = -4142

End Sub
 
Last edited:
Upvote 0
Thanks so much thats exactly what I needed. the 3 days was just an example, you gave me exactly what i need.... Thanks a lot for the help!
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,941
Latest member
AlphaRino

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