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
Helps is appreciated.
Thank you
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
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]
Regards,
Simon
Please read this before cross posting!
In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
If I have seen further it is by standing on the shoulders of giants.
Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)
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
pikeMe.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]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Hi there,
Great thanks for the quick solotions and option. I really appreciated all your assistance.
Thanks