Hi there,
I have two 2 textbox for input of dates. On the 3rd textbox I would like to show no of days between these 2 textbox.Any VBA to automate this
:doh: Helps is appreciated.
Thank you
Printable View
Hi there,
I have two 2 textbox for input of dates. On the 3rd textbox I would like to show no of days between these 2 textbox.Any VBA to automate this
:doh: Helps is appreciated.
Thank you
Assuming they are on the worksheet, you could try this in the workshet code module:
[vba]
Private Sub TextBox3_GotFocus()
Me.TextBox3.Value = CDate(Me.TextBox2.Value) - CDate(Me.TextBox1.Value) & " Days"
End Sub
[/vba]
hey tlchan
or possibly the excel "DateDiff" Function
[VBA]
Private Sub TextBox3_GotFocus()
Me.TextBox3.Value = DateDiff("yyyy",Me.TextBox2.Value,Me.TextBox1.Value)
End Sub
[/VBA]
pike
Hi Pike & Simon,
Thanks for your quick solution. Bothe codes work but the result showed in -ve value. How to overcome this?
Need your help again.
Hi tichan
try
pikeCode:Me.TextBox3.Value = DateDiff("yyyy",Me.TextBox1.Value,Me.TextBox2.Value)
IF either date could be the later, you could use
[vba]
Private Sub TextBox3_GotFocus()
Me.TextBox3.Value = Abs(CDate(Me.TextBox2.Value) - CDate(Me.TextBox1.Value) & " Days")
End Sub
[/vba]
Hi there,
Great thanks for the quick solotions and option. I really appreciated all your assistance.
Thanks