Share via

UserForm: Sum the values in Textboxes

Anonymous
2010-10-07T15:08:42+00:00

Hello.  I'm running into a problem trying to add four numeric values from TextBoxes in a UserForm.  This is what I'm trying to use:

SUMTOT = Controls("TextBox1").Value + Controls("TextBox2").Value + Controls("TextBox3").Value + Controls("TextBox4").Value

If the four values are 10, 5, 10 and 5 the result is a concatenated string:  105105.

I also tried it without the "Controls", parentheses and double quotes but it gave me an error.

Can someone please tell me how to correct this so that the result will be 30?

Thanks.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-10-07T15:51:53+00:00

The text boxes are returning strings so need data type conversion

SUMTOT = clng(Controls("TextBox1").Value) + clng(Controls("TextBox2").Value) etc

I believe you only need to using CLng on one of the TextBoxes as opposed to all of them... I think once one value is a real number, then addition (instead of concatenation) will take place automatically if the other text values are numeric characters.


NOTE: Please mark the message or messages (yes, you can mark more than one) that answer your question as the "Answer" so that others will know your question has been resolved.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2010-10-07T15:19:21+00:00

Hi,

The text boxes are returning strings so need data type conversion

SUMTOT = clng(Controls("TextBox1").Value) + clng(Controls("TextBox2").Value) etc


If this post answers your question, please mark it as the Answer.

Mike H

Was this answer helpful?

0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-10-07T15:20:43+00:00

    try

    If IsNumeric(Me.TextBox1.Value) _

     And IsNumeric(Me.extBox2.Value) _

     And IsNumeric(Me.TextBox3.Value) _

     And IsNumeric(Me.TextBox4.Value) Then

    Me.TxtTotalRe.Value = CDbl(Me.TextBox1.Value) _

                                   + CDbl(Me.extBox2.Value) _

                                   + CDbl(Me.TextBox3.Value) _

                                   + CDbl(Me.TextBox4.Value)

    end if

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more