VBA on userform for calculating age from text box entry

Kelly05201

New Member
Joined
Jun 17, 2016
Messages
29
For calculating a person's age, Courtesy of Ken Getz, Mike Gilbert, VBA Developers Handbook:
Code:
Function dhAge(dtmBD As Date, Optional dtmDate As Date = 0) _
 As Integer
    ' This procedure is stored as dhAgeUnused in the sample
    ' module.
    Dim intAge As Integer

    If dtmDate = 0 Then
        ' Did the caller pass in a date? If not, use
        ' the current date.
        dtmDate = Date
    End If
    intAge = DateDiff("yyyy", dtmBD, dtmDate)
    If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), _
     Day(dtmBD)) Then
        intAge = intAge - 1
    End If
    dhAge = intAge("#DOB#")
End Function

I'm trying to use this on my userform. I have a textbox on the userform named "DOB" where user enters mm/dd/yy... but can't figure out how to pass this value to use in the function. (I'll deal with how to verify the mm/dd/yy format later)
What will happen after that will be
Code:
If intAge > sheet1.cells("G9") Then Me.ComboBox1.Value = "Adult"
TIA for suggestions !
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi

Try:

Code:
If dhAge(Me.DOB) > Sheet1.Cells("G9") Then Me.ComboBox1.Value = "Adult"


Dave
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top