+ Reply to Thread
Results 1 to 6 of 6

Thread: No. in age range if age in years and months

  1. #1
    Registered User
    Join Date
    05-21-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    13

    No. in age range if age in years and months

    Stumped on how to count people in group 1 with age 4y 0m or more but less than 18y 0m.

    (4x8 worksheet attached with dates in format dd/mm/yy)
    Attached Files Attached Files
    Last edited by 13sydwest; 08-29-2011 at 06:24 AM.

  2. #2
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,575

    Re: No. in age range if age in years and months

    Can you use a helper cell...

    Add a column D for just the year

    In column D...D2 copied down =DATEDIF(B2,A2,"Y")

    =COUNTIFS($E$2:$E$7,1,$D$2:$D$7,">=4",$D$2:$D$7,"<=18")
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  3. #3
    Registered User
    Join Date
    05-21-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: No. in age range if age in years and months

    Thanks Jeff. Problem is that the helper cell (if I've understood it correctly) returns any age between 18y 0m and 18y 11m as "18".

    Say I want no. in group with age equal to or greater than 4 but less than or equal to 18.

    I've added a highlighted row to the worksheet where age of person is 18y 4m. Helper cell then shows this as 18. The COUNTIFS function includes this person in the age range requested and so returns an incorrect count.

    I guess I could get the helper cell to return age in months, or even better, in weeks to get a more accurate, yet possibly still incorrect, count.

    Syd
    Attached Files Attached Files

  4. #4
    Forum Guru ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    traded up
    MS-Off Ver
    2003 & 2010
    Posts
    1,905

    Re: No. in age range if age in years and months

    From your first sample spreadsheet, and without a helper column, you can use SUMPRODUCT like this:

    =SUMPRODUCT(--(D2:D8=1),--(A2:A8>=DATE(YEAR(B2:B8)+4,MONTH(B2:B8),DAY(B2:B8))),--(A2:A8<DATE(YEAR(B2:B8)+18,MONTH(B2:B8),DAY(B2:B8))))
    or COUNTIFS like this:

    =COUNTIFS(D2:D8,1,A2:A8,">="&DATE(YEAR(B2:B8)+4,MONTH(B2:B8),DAY(B2:B8)),A2:A8,"<"&DATE(YEAR(B2:B8)+18,MONTH(B2:B8),DAY(B2:B8)))
    but the COUNTIFS will require Ctrl-Shift-Enter.
    Last edited by ConneXionLost; 08-28-2011 at 02:46 AM.
    “To sin by silence when they should protest makes cowards of men.” ~ Abraham Lincoln

  5. #5
    Registered User
    Join Date
    05-21-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: No. in age range if age in years and months

    Many thanks. The SUMPRODUCT will be perfect for me.
    I tried the COUNTIFS (with the CTRL+SHIFT+ENTER) but could only get it to return "0" instead of 2. Not sure how I've applied it wrongly.
    Syd

  6. #6
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,806

    Re: No. in age range if age in years and months

    change the helper cell to give months
    =DATEDIF(B2,A2,"m")
    then its simply
    =SUMPRODUCT(--(D2:D9>=16),--(D2:D9<216),--(E2:E9=1))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

+ 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.2.0