Results 1 to 3 of 3

Thread: adding 3 months just to month part of date and highlighting relevant cells

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    1

    adding 3 months just to month part of date and highlighting relevant cells

    I have a list of employees and a start date wehn they joined the company.
    what i am trying to do is enter a formula where if the date is 3 months later then the trianing date then that particaular cell is flagged and changes colour.
    The hire date is formated as a medium date and i would like the relevant cells to be highlighted.

    EmployeeName Hire Date TrainingDate Retrain
    joe bloggs 29/07/2004 25/08/2004 No cell in red

    i think i need to inlcude a if statment in the formula and try and add 3 to the months part of the date by just selecting the month from training date.

    Does anyone know how to achieve this plz need some help

    Thanks

    Rich P

  2. #2
    Addicted Member
    Join Date
    Jan 2005
    Posts
    138

    Re: adding 3 months just to month part of date and highlighting relevant cells

    You have to intercept the change of the cell by using worksheet event.
    Something like this:

    VB Code:
    1. Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    2. On Error GoTo Err_Worksheet_Change
    3. Dim MyCell As Range
    4.  
    5. If Not Intersect(Target, Range("F2")) Is Nothing Then
    6. Set MyCell = Range("F2")
    7.  
    8.     Application.EnableEvents = False
    9.    
    10.     If MyCell > DateAdd("M", 3, MyCell.Offset(0, 1)) Then
    11.         With MyCell.Interior
    12.             .ColorIndex = 6
    13.             .Pattern = xlSolid
    14.         End With
    15.     End If
    16.     Set MyCell = Nothing
    17. End If
    18.  
    19. Err_Worksheet_Change:
    20. Application.EnableEvents = True
    21. Exit Sub
    22. End Sub
    Last edited by D-niss; Apr 24th, 2005 at 10:07 PM.

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: adding 3 months just to month part of date and highlighting relevant cells

    Conditional Formatting?


    Pls note that I do not have Winzip at this workplace (new job) so I've renamed to txt to upload.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width