Handy VBA To Calculate Person Age

This handy VBA procedure is just to show you how we can calculate and display someone Age. To do this, of course we need to know their date of birth first, then simply using datediff and mod vba functions we can calculate how old is he/she.

Sub PersonAge()
    Dim iYears As Integer, iMonths As Integer, iMonth As Integer
    Dim dtDateofbirth As Date

    dtDateofbirth = _
    CDate(InputBox("Input your date of birth (yyyy-mm-dd)", "Date of birth"))

    iYears = DateDiff("yyyy", CDate(dtDateofbirth), Date)
    iMonths = (DateDiff("m", CDate(dtDateofbirth), Date)) Mod (iYears * 12)

    MsgBox "Your age are " & iYears & " year(s) and " & iMonths & " month(s)"
End Sub

For this example, I use MsgBox and InputBox to get input and display the output data, but we can change it to worksheet cells reference if we want to integrate this calculation in our Excel Worksheet.

This entry was posted in Excel VBA Function and tagged , , . Bookmark the permalink.

13 Responses to Handy VBA To Calculate Person Age

  1. Pingback: ipad

  2. Pingback: natural search engine optimization services

  3. Pingback: natural search engine optimization

  4. Pingback: Homepage

  5. Pingback: free bingo hunter

  6. Pingback: mio liquid water enhancer

  7. Pingback: new music

  8. Pingback: scrapebox auto approve

  9. Pingback: Buy Comment Backlinks

  10. Pingback: Scrapebox Auto Approve

  11. Pingback: reverse mortgages

  12. Pingback: how does reverse mortgage work

  13. Pingback: poilsines keliones

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>