View Full Version : Solved: Days Difference between text box
tlchan
07-19-2008, 08:28 PM
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
Simon Lloyd
07-19-2008, 09:02 PM
Assuming they are on the worksheet, you could try this in the workshet code module:
Private Sub TextBox3_GotFocus()
Me.TextBox3.Value = CDate(Me.TextBox2.Value) - CDate(Me.TextBox1.Value) & " Days"
End Sub
hey tlchan
or possibly the excel "DateDiff" Function
Private Sub TextBox3_GotFocus()
Me.TextBox3.Value = DateDiff("yyyy",Me.TextBox2.Value,Me.TextBox1.Value)
End Sub
pike
tlchan
07-19-2008, 10:30 PM
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
Me.TextBox3.Value = DateDiff("yyyy",Me.TextBox1.Value,Me.TextBox2.Value)
pike
Bob Phillips
07-20-2008, 02:59 AM
IF either date could be the later, you could use
Private Sub TextBox3_GotFocus()
Me.TextBox3.Value = Abs(CDate(Me.TextBox2.Value) - CDate(Me.TextBox1.Value) & " Days")
End Sub
tlchan
07-20-2008, 03:14 AM
Hi there,
Great thanks for the quick solotions and option. I really appreciated all your assistance.
Thanks
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.