Kelly05201
New Member
- Joined
- Jun 17, 2016
- Messages
- 29
For calculating a person's age, Courtesy of Ken Getz, Mike Gilbert, VBA Developers Handbook:
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
TIA for suggestions !
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"