As a newbie I am working through a newbie book on VBA for excel, and I ran into a small issue. Below is the code to determine a persons birthdate and well it is giving me an inaccurate value (105), any ideas?
:::::::::::::::::Code::::::::::::::::::::::::
Function CalculateAge(birthDate As Date) As Byte
Dim birthdayNotPassed As Boolean
birthdayNotPassed = CDate(Month(birthDate) & "/" & _
Day(birthDate) & "/" & _
Year(Now)) > Now
CalculateAge = Year(Now) - Year(birthDate) + birthdayNotPassed
End Function
Sub TestIt ()
MsgBox CalculateAge (#2/27/1969#)
End Sub
::::::::::::::::End Code::::::::::::::::::::::::
When I run the TestIt subroutine the age is calculated fine, but when i use the function in the spreadsheet the value always calculates to 105, even as I type in one value at a time for example the month 2, and the value already is at 105, followed by / 27 and again the value is at 105 and finally / 1969 the value is still 105. Any ideas????
Thanks in advance
Aaron
:::::::::::::::::Code::::::::::::::::::::::::
Function CalculateAge(birthDate As Date) As Byte
Dim birthdayNotPassed As Boolean
birthdayNotPassed = CDate(Month(birthDate) & "/" & _
Day(birthDate) & "/" & _
Year(Now)) > Now
CalculateAge = Year(Now) - Year(birthDate) + birthdayNotPassed
End Function
Sub TestIt ()
MsgBox CalculateAge (#2/27/1969#)
End Sub
::::::::::::::::End Code::::::::::::::::::::::::
When I run the TestIt subroutine the age is calculated fine, but when i use the function in the spreadsheet the value always calculates to 105, even as I type in one value at a time for example the month 2, and the value already is at 105, followed by / 27 and again the value is at 105 and finally / 1969 the value is still 105. Any ideas????
Thanks in advance
Aaron
Code: