+ Reply to Thread
Results 1 to 3 of 3

Help with a formula using dates and empty cells

  1. #1
    Registered User
    Join Date
    01-19-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Help with a formula using dates and empty cells

    Hi Folks,

    Firstly, thanks in advance for anyone taking the time to help with this. I know we're all very busy!

    Secondly, apologies if this is too long, I'm just trying to be as detailed as possible.


    Right, I have a spreadsheet with all my members of staff on, names, addresses, pay rates, dates of employment, length of service etc. My problem is with the date of employment/length of service columns. What I currently do is have one table for current staff members, and one for ex-members of staff. So the "Current Staff" sheet doesn't have an "End Date" column, and when someone leaves I'll cutting and pasting the row into the the "Ex-Staff" sheet, which has an "End Date" column and that does the job. Which I guess is fine. But it would be really useful to have everything on one sheet for several reasons and I need a bit of help.

    I need the "Length of Service" column (a. it's useful & b. it affects holiday entitlement) and I've found a way of displaying it in Years, Months & Days (which is in place on the "Ex-Staff" sheet).

    The sheet I'm trying to do would have both current and ex staff on this new sheet. What I'd really like is to have a "Start Date" column, a "Leaving Date" column & a "Length of Service" column. The formula I'm having trouble with is for the "Service" column because I'd like it to do two things...

    1) If there is no data in the "Leaving Date" column I'd like the "Service" to work out [today's date-Start date]
    2) If there IS data in the "Leaving Date" column I'd like the "Service" column to work out [Leaving Date-Start Date]

    I know how to do these relatively simple things separately (hence me using two different sheets at the minute) and I'm assuming it's possible to do it in one cell? But I'm struggling!



    P.s. I'd also really like it if the whole row could turn red if there was a date in the "Leaving Date" column. Again, I'm sure I could do this pretty easily if it were a stand alone requirement but don't know how to get it to do all the things at once!

    Many Thanks,

    Chris

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Help with a formula using dates and empty cells

    Let's say C is the start date and F is the Leaving Date (when there is one) and G is the Length of service

    In G2 try

    =IF(F2<>0,TODAY()-C2,F2-C2)

    Part 2 (not sure if this is the same in Excel 2002)
    Select all your data A2:G100 or whatever
    Go to conditional formatting > use Formula (or custom)
    =$F2>0 format as color of your choice, "OK"

    Did that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor
    Join Date
    03-15-2007
    Location
    AL, USA
    MS-Off Ver
    2007
    Posts
    174

    Re: Help with a formula using dates and empty cells

    Here is your formula:
    =if(leavingdate="", datedif(startdate, today(), "DMY"), datedif(startdate, leavingdate, DMY))

    repalce leavingdate and startdate with your references. Replace DMY with "D" for days, "M" for months, or "Y" for years.

    conditional formatting like the person above said for the other part.

    Hoe I helped, and didn't have any typos for the formula
    Last edited by mshale; 06-27-2012 at 10:07 AM.

+ 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