I am a bit confused.
a) Is TextBox1 / Cell A2 the
End Date or the start date ?
b) You are populating ss & SS1 before you are populating the text boxes using A2 and B2.
Is it the intention to use the values from A2 and B2 ?
@Joe4 VBA DateDiff does not work the same as Excel DateDif ie:
Rich (BB code):
? DateDiff("m", "05/08/1985", "10/12/2024")
produces:
472
I am thinking you will need to use something like:
(originally posted by Chip Pearson but there are a few incorrect variations of this out there)
I am login off for the night but we can adapt this to fit your requirement once you clarify whether the intention is to use the values in A2 & B2 or not and which of is the start and which is the end value. Unless
@HighAndWilder can give you a solution after you answer his question.
VBA Code:
Function Age(Date1 As Date, Date2 As Date) As String
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim Temp1 As Date
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 > Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 > Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(Date2), Month(Date2), 0)) + D
End If
Age = Y & " years " & M & " months " & D & " days"
End Function