Convert birthday to age in days
To convert a date of birth to age, in days, we can apply the Excel DATEDIF and NOW functions
Example: Convert birthday to age in days
=DATEDIF(B5,NOW(),"d")
|
The formula returns the number of days from the specified date, which is the birthdate that we selected in this example, to the current date that is specified by the Excel NOW function.
|
Dim ws As Worksheet
Set date1 = ws.Range("B5")
ws.Range("C5") = DateDiff("m", date1, Now)
End Sub
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.
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.
METHOD 2. Convert birthday to age in days using VBA with a formula function
VBA
Dim ws As Worksheet
ws.Range("C5").Formula = "=DATEDIF(B5,Now(),""d"")"
End Sub
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.
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.
To convert a date of birth to age, in days, we can apply the Excel DATEDIF and NOW functions. If using VBA, we either use a DateDiff function or apply the DATEDIF formula.
=DATEDIF(birthdate,NOW(),"d")
ARGUMENTS
birhtdate: The birthdate of the person who's age you want to calculate.