+ Reply to Thread
Results 1 to 11 of 11

Date of birth and pop-up formula/VBA help in Excel

  1. #1
    Registered User
    Join Date
    05-29-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Date of birth and pop-up formula/VBA help in Excel

    Hi guys,

    I need to create a formula in Excel, but I don't know where to start.

    The spreadsheet will be used by bars to enter their staff details in. One of the fields will be the date of birth.

    If the date of birth entered means that they are not yet 18, I need a pop-up to say: "Bar staff must be 18 years or over"

    I don't know how to a) make a formula to tell me if the DOB makes them over 18 (do I need to update this formula every time we use it on a different date?), or b) how to create a pop-up.

    Any help would be massively appreciated.

    Thanks,
    Ryan
    Last edited by ryan-cook; 05-29-2013 at 11:13 AM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Urgent help with Formula/VBA in Excel

    "Hi and welcome to the forum

    We would love to help you with your question, but 1st, in accordance with forum rules, please rename your thread to something more meaningful, that actually describes your problem.

    Because thread titles are used in searching the forum it is vital they be written to accurately describe your thread content or overall objective using ONLY search friendly key words. That is, your title used as search terms would return relevant results.

    Many members will look at a thread title, and if it is of interest to them, or it falls within their area of expertise, they might only open those threads.

    Look at it this way...if you typed that title into google, what would you expect to get back?
    To change a Title on your post, click EDIT on you're 1st post, then Go Advanced and change your title"
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    05-29-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Urgent help with Formula/VBA in Excel

    No problem.

    Thanks.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Date of birth and pop-up formula/VBA help in Excel

    If you had today's date, =TODAY(), in cell A1 and the birth date in, say, cell B1, the following formula would give you the number of days:

    =$A$1-B1.

    So, =($A$1-B1)/365 would give you the number of years, give or take ... because it's not accounting for Leap Years.

    Or, you could use: =DATEDIF(B1,$A$1,"Y")


    Use Conditional Formatting to highlight dates that are less than 18.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    05-29-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Date of birth and pop-up formula/VBA help in Excel

    Thanks, TMS.

    Instead of Conditional Formatting, is there a way that I can get a pop-up to appear?

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Date of birth and pop-up formula/VBA help in Excel

    Thanks

    This wont flag you with a message, but it will highlight the cell with the color you choose. Assume your DoB is in A1 (adjust as needed)
    1. highlight the range you want to apply the conditional formatting to
    2. on the home tab, styles, select CF
    3. select new rule, select use formula
    4. enter =(TODAY()-A1)/365.25<=18 format fill RED

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Date of birth and pop-up formula/VBA help in Excel

    is there a way that I can get a pop-up to appear
    AFAIK only with VBA.

    Regards, TMS

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Date of birth and pop-up formula/VBA help in Excel

    I'm not sure how it works in 2010 but in 2003 you can could get the pop up box if you use data validation. The steps are like this, maybe someone can translate this into the 2010 version:
    -select the cell where the date of birth will be entered, in this example i will use A1
    -click data -> validation
    -Under allow, Select custom
    -In the formula box enter =IF((TODAY()-A1)/365.25>18,TRUE,FALSE)
    -click the error alert tab
    -enter the message you want to appear, e.g. "bar staff must be over 18"
    Last edited by ragulduy; 05-29-2013 at 11:48 AM.

  9. #9
    Registered User
    Join Date
    05-29-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Date of birth and pop-up formula/VBA help in Excel

    Thanks, guys.

    With a combination of the above, I think I'm almost there.

    I've got a =TODAY( ) formula in cell A1 on the spreadsheet, but I now need a formula aligned with this so that I can work out if someone is 18 or not.

    So, I just need something along the lines of... IF A1 IS "THIS" DATE, THEN THE DATE OF BIRTH ENTERED MEANS THAT THIS PERSON IS/ISN'T 18

    Hope that makes some kind of sense...

  10. #10
    Registered User
    Join Date
    05-29-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Date of birth and pop-up formula/VBA help in Excel

    Quote Originally Posted by ryan-cook View Post
    Thanks, guys.

    With a combination of the above, I think I'm almost there.

    I've got a =TODAY( ) formula in cell A1 on the spreadsheet, but I now need a formula aligned with this so that I can work out if someone is 18 or not.

    So, I just need something along the lines of... IF A1 IS "THIS" DATE, THEN THE DATE OF BIRTH ENTERED MEANS THAT THIS PERSON IS/ISN'T 18

    Hope that makes some kind of sense...
    Given that it is 2013, I guess I could just minus 5 years from the current date, which would work fine (until 2014). However, I'm not sure how I minus days/months/years in a formula.

  11. #11
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Date of birth and pop-up formula/VBA help in Excel

    Hello
    If your DOB is in say cell B1 the following formula should flag anyone under 18:

    Please Login or Register  to view this content.
    You could also hard code the Today() function:

    Please Login or Register  to view this content.
    Here there's no need to reference cell A1.

    Hope this helps.
    DBY

+ 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