Good day
i created a userform with two textboxes. when u type in two dates and press cmdbutton "Calculate", it should show the difference in years, months and days.
i found this piece of code on the internet make i do not want to use input and message boxes.
i prefer typing dates in textboxes and have the result if possible in a label.
u can change the final excel file any way you want.
here is the code;
Code
Sub ageCalculator()
Dim age As Integer, dob As Date, dt As Date
dob = InputBox("Enter Date of Birth")
dt = InputBox("Enter <age on> date")
years = IIf(dt > DateSerial(Year(dt), Month(dob), Day(dob)), DateDiff("yyyy", dob, dt), DateDiff("yyyy", dob, dt) - 1)
months = IIf(Day(dt) > Day(dob), Abs(Month(dob) - Month(dt)), Abs(Month(dob) - Month(dt)) - 1)
days = IIf(Day(dt) > Day(dob), Day(dt) - Day(dob), (Day(DateSerial(Year(dob), Month(dob) + 1, 1) - 1) - Day(dob)) + Day(dt))
Debug.Print years & "years " & months & "months" & days & "days"
End Sub
and i am attaching the file.
there is a source code in there but you can delete it and make it to work with the above code
Display More