![]() |
Sum numbers in userform
Hi there i use userform to sum the entered numbers into the same userform Code: -------------------- Private Sub CommandButton1_Click() If Label1.Caption = "" Then Label1.Caption = TextBox1.Value TextBox2.Value = TextBox1.Value Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & TextBox1.Value TextBox2.Value = TextBox2.Value + TextBox1.Value End If TextBox1.Value = "" End Sub -------------------- but this line: Code: -------------------- TextBox2.Value = TextBox2.Value + TextBox1.Value -------------------- put the numeric values next to each other i need to sum them insted ? -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
Sum numbers in userform
Hi Helmekki,
but this line: Code: -------------------- TextBox2.Value = TextBox2.Value + TextBox1.Value -------------------- put the numeric values next to each other i need to sum them insted ? Try: TextBox2.Value = CDbl(TextBox2.Value) + CDbl(TextBox1.Value) --- Regards, Norman "helmekki" wrote in message ... Hi there i use userform to sum the entered numbers into the same userform Code: -------------------- Private Sub CommandButton1_Click() If Label1.Caption = "" Then Label1.Caption = TextBox1.Value TextBox2.Value = TextBox1.Value Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & TextBox1.Value TextBox2.Value = TextBox2.Value + TextBox1.Value End If TextBox1.Value = "" End Sub -------------------- but this line: Code: -------------------- TextBox2.Value = TextBox2.Value + TextBox1.Value -------------------- put the numeric values next to each other i need to sum them insted ? -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
Sum numbers in userform
i tried with this code: Code: -------------------- Private Sub CommandButton1_Click() Dim tooo As Double Dim vtt As Double If Label1.Caption = "" Then Label1.Caption = vtt.Value tooo.Value = vtt.Value Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & vtt tooo.Value = CDbl(tooo) + CDbl(vtt) End If tooo.Value = "" End Sub -------------------- but it gives me invaled qualifier when tring to read vtt any idea how to solve the problem ? -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
Sum numbers in userform
Since vtt is an intrinsic data type (a double), it doesn't have
any properties. Your code tooo.Value = vtt.Value is wrong. It should be tooo = vtt The code tooo.Value = CDbl(tooo) + CDbl(vtt) is also wrong. First, you can't have a Value property, and since tooo and vtt are declared as double, you don't need the CDbl function at all. tooo= tooo + vtt -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "helmekki" wrote in message ... i tried with this code: Code: -------------------- Private Sub CommandButton1_Click() Dim tooo As Double Dim vtt As Double If Label1.Caption = "" Then Label1.Caption = vtt.Value tooo.Value = vtt.Value Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & vtt tooo.Value = CDbl(tooo) + CDbl(vtt) End If tooo.Value = "" End Sub -------------------- but it gives me invaled qualifier when tring to read vtt any idea how to solve the problem ? -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
Sum numbers in userform
I made some correction, but still got type mismatch in the line CDbl(tooo.Value) here is the whole code Code: -------------------- Private Sub CommandButton1_Click() Dim cdbltooo As Double Dim cdbltotv As Double If Label1.Caption = "" Then Label1.Caption = totv.Value tooo.Value = CDbl(totv.Value) Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & totv.Value tooo.Value = CDbl(tooo.Value) + CDbl(totv) End If tooo.Value = "" End Sub -------------------- -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
Sum numbers in userform
Did you read my reply? You still have .Value on your totv and
tooo variables. This WILL NOT WORK. Get rid of the .Value's. And you don't need the CDbl functions because your variables are already doubles. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "helmekki" wrote in message ... I made some correction, but still got type mismatch in the line CDbl(tooo.Value) here is the whole code Code: -------------------- Private Sub CommandButton1_Click() Dim cdbltooo As Double Dim cdbltotv As Double If Label1.Caption = "" Then Label1.Caption = totv.Value tooo.Value = CDbl(totv.Value) Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & totv.Value tooo.Value = CDbl(tooo.Value) + CDbl(totv) End If tooo.Value = "" End Sub -------------------- -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
Sum numbers in userform
Ok , i did what you said, but it did not work with me . still tooo TextBox does not show the total amount entered in vtt each time i enter a new number............. i need the tooo to show the total of numbers entered into vtt each time here is the code and please find the attached file Code: -------------------- Private Sub CommandButton1_Click() Dim tooo As Double Dim vtt As Double If Label1.Caption = "" Then Label1.Caption = vtt tooo = vtt Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & vtt tooo = tooo + vtt End If tooo = "" End Sub -------------------- -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
Sum numbers in userform
Your last command is
tooo = "" so it you clear whatever it may have shown from the earlier code. Also, don't dimension tooo as Double if it is a textbox. Don't dimension it at all. Assuming tooo and vtt are textboxes on your form Private Sub CommandButton1_Click() If Label1.Caption = "" Then Label1.Caption = vtt tooo.Value = vtt.Value Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & vtt tooo.Value = val(tooo.value) + val(vtt.Value) End If End Sub -- Regards, Tom Ogilvy "helmekki" wrote in message ... Ok , i did what you said, but it did not work with me . still tooo TextBox does not show the total amount entered in vtt each time i enter a new number............. i need the tooo to show the total of numbers entered into vtt each time here is the code and please find the attached file Code: -------------------- Private Sub CommandButton1_Click() Dim tooo As Double Dim vtt As Double If Label1.Caption = "" Then Label1.Caption = vtt tooo = vtt Else: Label1.Caption = Label1.Caption & vbCr Label1.Caption = Label1.Caption & vtt tooo = tooo + vtt End If tooo = "" End Sub -------------------- -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
Sum numbers in userform
Tom Ogilvy, realy thank u veru much it worked great for me -- helmekki ------------------------------------------------------------------------ helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939 View this thread: http://www.excelforum.com/showthread...hreadid=486630 |
All times are GMT +1. The time now is 10:48 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com