Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Calculating TextBoxes

When I change TextBox12 I would like the value of TextBox13 to be
TextBox12 - TextBox11/24 .

Is this possible?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default Calculating TextBoxes

Sure, put the calculation code in the Textbox12_Change event.

HTH. Best wishes Harald

"Patrick C. Simonds" wrote in message
...
When I change TextBox12 I would like the value of TextBox13 to be
TextBox12 - TextBox11/24 .

Is this possible?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Calculating TextBoxes

I created a small userform with 3 textboxes, a label and two commandbuttons.

This seemed to work ok:

Option Explicit
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If DoCalc(Me.TextBox1) = True Then
'ok
Else
Cancel = True
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If DoCalc(Me.TextBox2) = True Then
'ok
Else
Cancel = True
End If
End Sub
Private Sub UserForm_Initialize()

With Me.Label1
.Caption = ""
.ForeColor = vbRed
End With

Me.TextBox1.Tag = "ID here"
Me.TextBox2.Tag = "Other ID here"

With Me.CommandButton1
.Caption = "Ok"
.Default = True
End With

With Me.CommandButton2
.Caption = "Cancel"
.Cancel = True
.TakeFocusOnClick = False
End With

End Sub
Function DoCalc(myTB As MSForms.TextBox) As Boolean
If IsNumeric("0" & Me.TextBox1.Value) _
And IsNumeric("0" & Me.TextBox2.Value) Then
Me.TextBox3.Value = CDbl("0" & Me.TextBox1.Value) _
- (CDbl("0" & Me.TextBox2.Value) / 24)
Me.Label1.Caption = ""
DoCalc = True
Else
Me.Label1.Caption = "Please enter a number in: " & myTB.Tag
DoCalc = False
End If
End Function

I used this kind of thing:
IsNumeric("0" & Me.TextBox1.Value)
so that an empty textbox would be treated as 0.

"Patrick C. Simonds" wrote:

When I change TextBox12 I would like the value of TextBox13 to be
TextBox12 - TextBox11/24 .

Is this possible?


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textboxes Not Calculating Properly RyanH Excel Programming 3 February 14th 08 01:40 PM
Textboxes not Calculating properly RyanH Excel Programming 6 December 13th 07 01:42 PM
Show Results in TextBoxes, ONLY if All TextBoxes have Data in them RyanH Excel Programming 3 November 19th 07 03:30 PM
calculating textboxes enyaw Excel Programming 1 July 13th 06 03:03 PM
Calculating with textboxes.... Mark Rosenkrantz Excel Programming 4 November 23rd 03 12:42 PM


All times are GMT +1. The time now is 11:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"