D delta Member Jun 17, 2018 #1 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
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
Belleke Well-Known Member Jun 17, 2018 #2 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
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