Consulting

Results 1 to 4 of 4

Thread: tab colour

  1. #1
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location

    tab colour

    Hi, I'm trying to change the colour of the worksheet tab to yellow if a date in cell AD5 is within 7 +/- days of today(NOW())?
    Only other thing to note is the date in cell AD5 is a hire date. So it may be eg "Mar 15 2001". I am trying to flag the tab by going yellow for me to reset the information in the tab because its within 7 days +/- of their anniversary..

    Any help is appreciated. Thanks.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,454
    Location
    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "D5" '<<<< change to suit

    On Error GoTo ws_exit

    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

    With Target

    If IsDate(.Value) Then

    Me.Tab.ColorIndex = xlColorIndexNone
    If Abs(.Value - Date) <= 7 Then

    Me.Tab.Color = vbYellow
    End If
    End If
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]

    This is worksheet event code.
    To implement it, select the sheet tab, right click, and
    select View Code.
    Paste this code into the code module that opens in the
    VBIDE.
    Then close the VBIDE and test it in Excel.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    Firstly thanks for the quick reply. But it seems that only if "D5" changes will it go yellow. Can we not get this in a worksheet calculate event as there will be time I do not change anything on the sheet and I need it to ture yellow if within the 7 days?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,454
    Location
    You could use the calculate event

    [vba]

    Private Sub Worksheet_Calculate()

    With Me.Range("D5")

    If IsDate(.Value) Then

    Me.Tab.ColorIndex = xlColorIndexNone
    If Abs(.Value - Date) <= 7 Then

    Me.Tab.Color = vbYellow
    End If
    End If
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •