Can multiple textbox exit scripts be combined?

Fyr

Active Member
Joined
Jan 20, 2009
Messages
375
I have another 100 textboxes that each have textbox#_exit scripts.
I was wondering if they can be combined into 1 exit script?
Here's a short example of the scripts:

Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label95.Caption = CDbl(TextBox1.Value) + CDbl(TextBox2.Value) + CDbl(TextBox3.Value) + CDbl(TextBox4.Value) + CDbl(TextBox5.Value) + CDbl(TextBox6.Value)
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label95.Caption = CDbl(TextBox1.Value) + CDbl(TextBox2.Value) + CDbl(TextBox3.Value) + CDbl(TextBox4.Value) + CDbl(TextBox5.Value) + CDbl(TextBox6.Value)
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label95.Caption = CDbl(TextBox1.Value) + CDbl(TextBox2.Value) + CDbl(TextBox3.Value) + CDbl(TextBox4.Value) + CDbl(TextBox5.Value) + CDbl(TextBox6.Value)
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label95.Caption = CDbl(TextBox1.Value) + CDbl(TextBox2.Value) + CDbl(TextBox3.Value) + CDbl(TextBox4.Value) + CDbl(TextBox5.Value) + CDbl(TextBox6.Value)
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label95.Caption = CDbl(TextBox1.Value) + CDbl(TextBox2.Value) + CDbl(TextBox3.Value) + CDbl(TextBox4.Value) + CDbl(TextBox5.Value) + CDbl(TextBox6.Value)
End Sub
Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label95.Caption = CDbl(TextBox1.Value) + CDbl(TextBox2.Value) + CDbl(TextBox3.Value) + CDbl(TextBox4.Value) + CDbl(TextBox5.Value) + CDbl(TextBox6.Value)
End Sub

thanks for taking a look!
 
For what you're doing (I'm assuming you're trying to keep a running total on Label95 of all your text boxes.. You can do the following to reduce the amount of typing, but with your method you'll still need to process each box indepedantly.. you may want to consider an ONKEY event instead... but .. here ya go..

Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call TBdo
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call TBdo
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call TBdo
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call TBdo
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call TBdo
End Sub
[B][COLOR=blue]Private Sub TBdo()[/COLOR][/B]
[B][COLOR=blue]  [COLOR=green]'only have to type the long line once..[/COLOR][/COLOR][/B][COLOR=blue]
[B]   Label95.Caption = CDbl(TextBox1.Value) + CDbl(TextBox2.Value) + CDbl(TextBox3.Value) + CDbl(TextBox4.Value) + CDbl(TextBox5.Value) + CDbl(TextBox6.Value)[/B]
[B]End Sub[/B]
[/COLOR]
 
Upvote 0
Thanks for the response!
I'll try that, but the reason i'm asking to see a shorter version is because some computers here at my workspace are old and can't handle all those long scripts. Some computer's crash after exiting the first textbox, while so others don't.

What is ONKEY event do?
 
Upvote 0
Maybe just calculate it all at once without having to do it after every exit... or after every 10th Text Box

ie..: If you have 100 Textboxes to evaluate.. perhaps..
Code:
Private Sub commandbutton1_click()
  For x = 1 to 100
     t_tot = t_tot + controls("Textbox" & x) + t_tot
  Next x
  [COLOR=black]Label95.Caption = Format(t_tot,"$ #,000.00")  'Assumes these are currency.. adjust to suit[/COLOR]
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top