Date and Time Function

atrembla

New Member
Joined
Jan 24, 2005
Messages
4
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:
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,206,761
Messages
6,074,786
Members
446,088
Latest member
Koustubh12

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