1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Option Explicit
Public Function AGE(ByVal dtBirthday As Date) As Integer
If Int(dtBirthday) > 0 Then Select Case Month(Date()) Case Is < Month(dtBirthday) AGE = Year(Date()) - Year(dtBirthday) - 1 Case Is = Month(dtBirthday) If Day(Date) >= Day(dtBirthday) Then AGE = Year(Date()) - Year(dtBirthday) Else AGE = Year(Date()) - Year(dtBirthday) - 1 End If Case Is > Month(dtBirthday) AGE = Year(Date()) - Year(dtBirthday) End Select Else AGE = CVErr(xlErrNA) End If End Function
|