Calculating age in VBA

Lucien

Board Regular
Joined
Oct 16, 2002
Messages
131
Hi,
First of all a happy new year to all of you.
I want to calculate the age of a person in VBA. In normal Excel in use the Yearfrac function for this. However this seems not to work in VBA as VBA does not recognise this worksheetfunction.
Is there an other method of calculating the exact age when the date of birth and the date of today is given?. Dividing the difference of the two dates by 365 does not give the good result.
Thanks in advance for your replies,
Lucien
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I realize that dividing by 365 does not yield accurate results, since it does not account for leap year. However if you divide by 365.25 (for 1 extra day every 4 years), you will either be exact or off by a very small number. That is how we handle the situation here, and it works well for us.
 
Upvote 0
Thanks,
If there is no other method to get the exact result I will use your solution.

Regards,
Lucien
 
Upvote 0
Hi,

VBA has its own Datediff syntax as follows:

Dim FirstDate, SecondDate as Date
Age = DateDiff("yyyy",FirstDate,SecondDate)

edit: This should be a built-in function in XL2000+

HTH,
Corticus
This message was edited by corticus on 2003-01-02 13:58
 
Upvote 0
On 2003-01-02 14:25, Barry Katcher wrote:
Weird! I used the DATE.DIFF function on my mchine, and it's coming up in French. Anyone know why?


Do you have Morefunc installed?
I think Date.diff is from that Add-in.


Age in Years

lookup help on YearFrac and try Datedif.

Caution: With a variety of dates, these functions are not accurate.
 
Upvote 0
On 2003-01-02 15:38, Barry Katcher wrote:
No, Dave. I have it loaded at home but not at the office. Do you have the URL? Appreciate.

Date.diff is from Morefunc.

Datedif is a regular function in most versions of Excel. It was only documented in Excel 2000.

Barry Do you mean the UrL for Morefunc?

Download the morefunc add-in from

http://longre.free.fr/english/index.html

and install/activate the add-in via Tools|Add-Ins.
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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