Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Adding values in textboxes...

Hi Gary,

Gary Phillips wrote:
I've got four textboxes... The first three are enabled, the fourth is
not.

I want the user to be able to enter an integer value into the first
three and it will add those three values into the fourth box. I do
not want the user to have to press any buttons, I want it to update
as the user goes along.


Something like this should work for you:

Private Sub TextBox1_Change()
CalcTotal
End Sub

Private Sub TextBox2_Change()
CalcTotal
End Sub

Private Sub TextBox3_Change()
CalcTotal
End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As _
MSForms.ReturnInteger)
If KeyAscii < Asc("0") Or KeyAscii Asc("9") Then
Interaction.Beep
KeyAscii = 0
End If
End Sub

Private Sub TextBox2_KeyPress(ByVal KeyAscii As _
MSForms.ReturnInteger)
If KeyAscii < Asc("0") Or KeyAscii Asc("9") Then
Interaction.Beep
KeyAscii = 0
End If
End Sub

Private Sub TextBox3_KeyPress(ByVal KeyAscii As _
MSForms.ReturnInteger)
If KeyAscii < Asc("0") Or KeyAscii Asc("9") Then
Interaction.Beep
KeyAscii = 0
End If
End Sub

Private Sub CalcTotal()
TextBox4.Text = CLng("0" & TextBox1.Text) + _
CLng("0" & TextBox2.Text) + _
CLng("0" & TextBox3.Text)
End Sub


You'll probably want to set the MaxLength property of the 3 textboxes to
something manageable to avoid overflow errors.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

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
Adding mm:ss values Howard Kaikow Excel Worksheet Functions 10 August 13th 09 05:21 PM
Axes values changes autmatically / textboxes lose formatting Anand Nichkaode Charts and Charting in Excel 5 March 28th 08 04:30 PM
Adding numerical values based on multiple values in another column Kazmaniac Excel Worksheet Functions 6 April 4th 07 08:53 PM
Adding the values of 2 textboxes Ben Allen Excel Programming 3 April 29th 04 09:05 PM
Add values of textboxes together Candee[_10_] Excel Programming 4 December 5th 03 07:05 PM


All times are GMT +1. The time now is 11:12 AM.

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

About Us

"It's about Microsoft Excel"