Thread: textbox autosum
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Woodi2 Woodi2 is offline
external usenet poster
 
Posts: 61
Default textbox autosum

Brilliant, thanks for that and the quick response.
The only other problemt I have with it is it returns the date in the
following format in the textbox i.e. 01/29/2009. When I click OK it then
changes it to 29/01/2009. How do I change the textbox so that it displays as
29/01/2009 so the user can check the date is correct.
Thanks
Ian

"OssieMac" wrote:

Hi Woodi,

Try this. It updates after you press enter or tab from TextBox1 or TextBox2

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Call UpdateWhenChanged

End Sub

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Call UpdateWhenChanged

End Sub

Sub UpdateWhenChanged()

If TextBox1.Value = "" Then Exit Sub
If TextBox2.Value = "" Then Exit Sub
TextBox3.Value = CDate(TextBox1.Value) + CDbl(TextBox2.Value)

End Sub
--
Regards,

OssieMac


"Woodi2" wrote:

Hi, I have created a userform with 3 textboxes, box1 = Date, box2 = Number of
days and Box3 = box 1 = box 2.
I have a code that almost works, see below.
heres what I want it to do.
Box 1 is a date and box 2 is a number. I want to add the these 2 values
together and display the answer in Box 3. The code works however I have to
select Box 3 and then press any key for it to calculate the sum. Is their a
way to autosum this and display the answer in the textbox.
Private Sub TextBox3_Change()
If TextBox1.Value = "" Then Exit Sub
If TextBox2.Value = "" Then Exit Sub
TextBox3.Value = CDate(TextBox1.Value) + CDbl(TextBox2.Value)
End Sub
Thanks