+ Reply to Thread
Results 1 to 8 of 8

Calculate Exact Age in Userform

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2003
    Posts
    68

    Calculate Exact Age in Userform

    Good afternoon all,

    I have a userform in which in one of the txtfields, I enter the Date of Birth. I format the entry to dd.mm.yyyy

    The code I am trying to use bugs out on the 4th line while trying to calculate the age and I can't seem to figure this one out.

    Any help would be awesome

    Please Login or Register  to view this content.

    Tayler

  2. #2
    Registered User
    Join Date
    08-08-2012
    Location
    UAE
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Calculate Exact Age in Userform

    Try in the 4th line:

    txtAge1.formula = Fix((DateDiff("d", txtDOB1.Value, Now) / 365.25))

  3. #3
    Registered User
    Join Date
    08-23-2012
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Calculate Exact Age in Userform

    Sorry to say .. no go.
    It Yellowed the Private sub line and blue highlighted '.Formula ='

    Any other ideas?

  4. #4
    Registered User
    Join Date
    08-08-2012
    Location
    UAE
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Calculate Exact Age in Userform

    Try:

    txtAge1.text = Fix((DateDiff("d", txtDOB1.Value, Now) / 365.25))

    Just to be clear, you want the age to appear in text box (txtAge1) based on DOB entered in txtDOB1?

  5. #5
    Registered User
    Join Date
    08-23-2012
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Calculate Exact Age in Userform

    nope .. tried that one myself. Doesn't work

    Yes, when I enter the date of birth into txtDOB1, eg, 19.04.1973, it will calculate the exact age (39) into txtAge1.

    It has to have something to do with the Format line.
    If I blank out the format line, the date appears under the original code.

    Which is why I said in the post that I format the value of txtDOB1 to DD.MM.YYYY

    So I would assume as soon as I do, it no longer becomes a date, and becomes just text.
    Last edited by twitch73; 09-11-2012 at 02:53 AM.

  6. #6
    Registered User
    Join Date
    08-23-2012
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Calculate Exact Age in Userform

    I got .. after typing that it hit me .. reverse the code, so it does the age first, THEN formats the date.

    [code]
    Private Sub txtDOB1_AfterUpdate()
    Set dValue = txtDOB1
    txtAge1.Value = Fix((DateDiff("d", txtDOB1.Value, Now) / 365.25))
    txtDOB1.Value = Format(dValue, "DD.MM.YYYY")
    End Sub
    [\code]

    Thanks for helping me brainstorm

    Tayler

  7. #7
    Registered User
    Join Date
    08-08-2012
    Location
    UAE
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Calculate Exact Age in Userform

    Great! Learnt something new myself

  8. #8
    Forum Contributor stojko89's Avatar
    Join Date
    05-18-2009
    Location
    Maribor, Slovenia
    MS-Off Ver
    MS Office 365
    Posts
    913

    Re: Calculate Exact Age in Userform

    That was it? Lol....guess it has to be like that for the code to work in excel 2003 in excel 2007 it works fine both ways

+ 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