Convert birthday to exact age
To convert a date of birth to the exact age, which is split into days, months and years, we can apply the Excel DATEDIF and NOW functions
Example: Convert birthday to exact age
Sub Convert_birthday_to_exact_age()
'declare variables
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'convert the birthdate to age
ws.Range("C5").Formula = "=DATEDIF(B5,NOW(),""y"")&"" years, ""&DATEDIF(B5,NOW(),""ym"")&"" months, ""&DATEDIF(B5,NOW(),""md"")&"" days"""
ws.Range("C5").Formula = "=DATEDIF(B5,NOW(),""y"")&"" years, ""&DATEDIF(B5,NOW(),""ym"")&"" months, ""&DATEDIF(B5,NOW(),""md"")&"" days"""
End Sub
OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named Analysis.
Birthday: If using the exact VBA code the birthday needs to be captured in cell ("B5").
Worksheet Name: Have a worksheet named Analysis.
Birthday: If using the exact VBA code the birthday needs to be captured in cell ("B5").
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Birthday: Select the cell that captures the birthday by changing the cell reference ("B5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
EXPLANATION
To convert a date of birth to the exact age, which is split into days, months and years, we can apply the Excel DATEDIF and NOW functions.
To convert a date of birth to the exact age, which is split into days, months and years, we can apply the Excel DATEDIF and NOW functions.
FORMULAS
=DATEDIF(birhtdate,NOW(),"y")&" years, "&DATEDIF(birhtdate,NOW(),"ym")&" months, "&DATEDIF(birhtdate,NOW(),"md")&" days"
=DATEDIF(birhtdate,NOW(),"y")&" years, "&DATEDIF(birhtdate,NOW(),"ym")&" months, "&DATEDIF(birhtdate,NOW(),"md")&" days"
ARGUMENTS
birhtdate: The birthdate of the person who's age you want to calculate.