# Place age in cell

##### Active Member
The following code places the age in column "E" when the date of birth is written in column "D"

Code:
``````Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 Then
Target.Offset(, 1).Formula = "=IF(DATEDIF(RC[-1],NOW(),""y"")>0,DATEDIF(RC[-1],NOW(),""y"") & "" years"",IF(DATEDIF(RC[-1],NOW(),""m"")>0,DATEDIF(RC[-1],NOW(),""ym"") & "" months"",DATEDIF(RC[-1],NOW(),""y"")))"
End If
End Sub``````
How could I change the code so that it places the age in cell "I14" when the date of birth is written in cell "K9"

Any help on this would be kindly appreciated.

### Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try

Code:
``Range("I14").Value = DateDiff("yyyy", Date, Range("K9").Value)``

Thanks for the help. But the code as places the age with a minus figure. For example if the age is written as 16/1/1980 it places the age as -31. Instead of 31 Years.

How could this be overcome?

I had it the wrong way round. Reverse the 2nd and 3rd arguments,

I'm sorry I couldn't understand. If you don't mind em asking; how shall I do that?

This is not rocket science

Code:
``Range("I14").Value = DateDiff("yyyy", Range("K9").Value, Date)``

Thanks for the reply Peter. But your line of code is giving only the numerical value. Meaning it does not say 16 Years or 12 Months. Instead it gives 16 or 12.

How could the code be adjusted so that it gives age in years?

Any help on this would be kindly appreciated.

Note: I'm aware this is not rocket science but people do misunderstand and makes mistakes.

Do you mean

Code:
``range("I14").Value = DateDiff("yyyy", range("K9").Value, Date) & " years"``

Yeah I did mean so. But if I write the date as 1/1/2011 the code is giving me the result as 0 Years instead of giving 2 Months. Also if write 1/3/2011 still it gives 0 Years instead of giving 8 days.

How could this be avoided. I mean calculate the age as either years, months or days individually?

Just put this formula in I14

=IF(K9="","",DATEDIF(K9,TODAY(),"y")&" y "&DATEDIF(K9,TODAY(),"ym")&" m "&DATEDIF(K9,TODAY(),"md") &" d")

Replies
1
Views
225
Replies
12
Views
2K
Replies
12
Views
1K
Replies
6
Views
882
Replies
17
Views
2K

1,220,986
Messages
6,157,229
Members
451,406
Latest member
Kevin_267

### 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.

### Which adblocker are you using?

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

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