+ Reply to Thread
Results 1 to 8 of 8

Change font color based on a validation check!

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2006
    Posts
    28

    Change font color based on a validation check!

    I have a simple worksheet which contains dates for specific events through out the years. Each event has an expiry date (2 yrs), so I would like to test D3 to Q16 (RangeName: "EventDates") to see if they have expired, and if so they will change Font Color to RED otherwise they will remain in BLUE.

    ie: if an event was done back in 22-Jan-05, it's due date would be 22-Jan-07. So it means that based on today's date, it has expired already, so instead of having a blue font, it will then change to Red.

    Can anyone help out with this one?

  2. #2
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302
    Look at the attached workbook

    The conditional format formula you could use is:
    =DATE(YEAR(A4)+2,MONTH(A4),DAY(A4))<NOW()

    Select a Pattern as the color you want
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-05-2006
    Posts
    28
    Quote Originally Posted by FrankBoston
    Look at the attached workbook

    The conditional format formula you could use is:
    =DATE(YEAR(A4)+2,MONTH(A4),DAY(A4))<NOW()

    Select a Pattern as the color you want

    Can this be done using VBA? I am using Excel 2007 and would like this using Conditional formatting but with VBA.

    Is this possible in 2007?


    The range I want this to check upon entry (ie: OnEntry), is from Range("D3:Q16"), if a cell contains nothing then nothing will be changed, if a cell has a date then check to see if 2 yrs have passed since that day, if so then change its color to RED thereby letting me know that that event has expired.

    ??

  4. #4
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302

    VBA or manual assignment of conditional formats

    The VBA solution would be to have a sub search the range of dates, check each one for expiration, and set the font color to blue or red. You probably wouldn't use Conditional Formatting.

    I suppose you could use a sub to assign the conditional format to the rectangle of date cells.

    Or, you can Edit: Copy: Paste - Formats (includes conditional formats) to the range holding the dates.

    Why is your preference for VBA in this case?

  5. #5
    Registered User
    Join Date
    12-05-2006
    Posts
    28
    Quote Originally Posted by FrankBoston
    The VBA solution would be to have a sub search the range of dates, check each one for expiration, and set the font color to blue or red. You probably wouldn't use Conditional Formatting.

    I suppose you could use a sub to assign the conditional format to the rectangle of date cells.

    Or, you can Edit: Copy: Paste - Formats (includes conditional formats) to the range holding the dates.

    Why is your preference for VBA in this case?

    Mainly because I am trying to gear towards VBA and the more I learn the better, I am trying to do everything using VBA....just to have a programming experience I suppose.

  6. #6
    Registered User
    Join Date
    08-03-2007
    Posts
    1
    Quote Originally Posted by Salmerin
    I have a simple worksheet which contains dates for specific events through out the years. Each event has an expiry date (2 yrs), so I would like to test D3 to Q16 (RangeName: "EventDates") to see if they have expired, and if so they will change Font Color to RED otherwise they will remain in BLUE.

    ie: if an event was done back in 22-Jan-05, it's due date would be 22-Jan-07. So it means that based on today's date, it has expired already, so instead of having a blue font, it will then change to Red.

    Can anyone help out with this one?
    Hi,

    I'm looking for something along the same lines, only I want something that changes colour with dates as it approaches deadline (in blue) and past deadline (in bold red). It's for a task list for work. I used to work with something like this but I didn't set it up so not a clue where to start. Can anyone help?

  7. #7
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302

    VBA sub checks dates and sets colors

    ' Find each cell in named range, check date
    ' Apply font color according to age
    '
    Sub ColorDates()
      Dim j As Long, twoYrs As Date
      'two years ago
      twoYrs = DateSerial(Year(Date) - 2, Month(Date), Day(Date))
    
    For Each ss In ActiveSheet.Range("EventDates")
      If Not IsDate(ss) Then GoTo skip
      If ss > twoYrs Then
        ss.Font.ColorIndex = 5 'set font to Blue
      Else
        ss.Font.ColorIndex = 3 'set font to Red
      End If
    skip:
      Next ss
    End Sub

  8. #8
    Registered User
    Join Date
    12-05-2006
    Posts
    28
    Quote Originally Posted by FrankBoston
    ' Find each cell in named range, check date
    ' Apply font color according to age
    '
    Sub ColorDates()
      Dim j As Long, twoYrs As Date
      'two years ago
      twoYrs = DateSerial(Year(Date) - 2, Month(Date), Day(Date))
    
    For Each ss In ActiveSheet.Range("EventDates")
      If Not IsDate(ss) Then GoTo skip
      If ss > twoYrs Then
        ss.Font.ColorIndex = 5 'set font to Blue
      Else
        ss.Font.ColorIndex = 3 'set font to Red
      End If
    skip:
      Next ss
    End Sub
    Thanks, this works for me!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1