Age calculation in Text Format, in year, month and day.

harzer

Board Regular
Joined
Dec 15, 2021
Messages
153
Office Version
  1. 2016
Platform
  1. Windows
I am facing a problem despite my research on the net, I confess that I can not find it.
Namely that I am unable to handle array variables correctly, which complicates my task.

I have a large amount of row data, in 10 columns, the ones that concern the present case, are columns E and H.
for now, column E is empty.
Column H contains dates of birth.
How to proceed, either by table or table combined with dictionary to indicate the age in: year, month and days in column E, according to the current date.
The goal is to have the result in text format, (Example: 15y 5m 10d), I thought of making a call to a function which would give the result just in text so as not to use formulas (No formulas) Please .
Unless I am mistaken, the desired result for the first 10 lines is in column L, based on the date that the calculation was made is: 30-01-2023
Thank you very much in advance for your suggestions.
PS: I completely emptied my table and I simply left the two columns concerned so that you can (eventually) test your code.
CalculAge1.xlsm
ABCDEFGHIJKLM
1AgeNé(e)Age
216-03-195765 a 10 m 14 j
317-04-201210 a 9 m 13 j
414-04-201210 a 9 m 16 j
525-03-196656 a 10 m 5 j
630-05-195963 a 8 m 0 j
717-02-196260 a 11 m 13 j
822-01-195568 a 0 m 8 j
915-02-196161 a 11 m 15 j
1018-04-201210 a 9 m 12 j
111-01-201013 a 0 m 29 j
1222-03-2019
1315-04-2007
1415-04-2007
1515-04-2007
1616-04-2007
1715-04-2008
1815-04-2008
1915-04-2008
2015-04-2008
2115-04-2008
2215-04-2008
2315-04-2008
2415-05-2008
2515-04-2008
Parents
 
By the way, just out of curiosity ...

What is precisely the formula you are currently working with ? say, in cell L2 ...
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
For your info, the macro CalcAges was tested and re-tested with many different Date formats for column H ... with no problem ... :)
 
Upvote 0
Hello Alex Blankenburg and James006,
Waw, Bravo and thank you both, your two proposals meet my expectations and are executed quickly.
My proposal works line by line, it's slower!
An additional thank you to James006 because he has been present since the beginning of my request.
Sincerely.
 
Upvote 0
Thanks a lot for your Thanks :)

Just out of curiosity, what is precisely the formula you are currently working with ? say, in cell L2
 
Upvote 0
As far as speed is concerned
arr(i) = Evaluate("=DATEDIF(" & CLng(Cells(i + 2, 8).Value) & ",TODAY(),""y"")&"" a ""&DATEDIF(" & CLng(Cells(i + 2, 8).Value) & ",TODAY(),""ym"")&"" m ""&DATEDIF(" & CLng(Cells(i + 2, 8).Value)
I didn't get an obvious errors but it is generally not advisable to use the "md" version of DateDif.
Per Microsoft here: DATEDIF function - Microsoft Support
Important: We don't recommend using the "MD" argument, as there are known limitations with it. See the known issues section below.

@harzer in checking for issue with md in James's code I had a look at the actual calculation you were using. I can see that it comes from Chip (Charles) Pearon's site but it would seem to have an error in it.
I believe that this line should not have a "+ 1" in the month section. We want the last day of the previous month not of the current month.
Happy to be proven wrong on this, if someone wants to confirm.

Rich (BB code):
' Currently
'D = Day(DateSerial(Year(DateCurrent), Month(DateCurrent) + 1, 0)) + D + 1
' Should be
D = Day(DateSerial(Year(DateCurrent), Month(DateCurrent), 0)) + D + 1

PS: the + 1 at the very end is your call, by adding 1 to the end it is including the Start Date as well as the End Date.
 
Upvote 0
Hello,
I took note of your remark and I put the old line in comment and I implemented yours.
I would see by testing, if problem, I put in application the code that I put in comment. The one with the (+1).
Cheers.
 
Upvote 0
Hello,
I tested your code, it works well and I am satisfied, thank you and congratulations.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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