• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Date Diff in Userform Textbox

delta

Member
Textbox 1 is today date
Textbox 2 is user enter any date
Textbox 3 show date diff between Textbox 1 - Textbox 2
by vba macro
how it calculate
 
This ciode is for a userform.
Code:
Private Sub UserForm_Initialize()
TextBox1.Value = Format(Date, "dd/mm/yyyy")
TextBox2.Value = Format(TextBox2, "dd/mm/yyyy")
End Sub
and
Code:
Private Sub Textbox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  TextBox3.Value = DateDiff("yyyy", DateValue(TextBox1.Value), TextBox2.Value)
End Sub
Date diff in years
or
Code:
Private Sub Textbox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  TextBox3.Value = DateDiff("d", DateValue(TextBox1.Value), TextBox2.Value)
End Sub
Date diff in days
 
Back
Top