0 votes
in VBA by Beginner (48 points)


i need hlep about sum format numbers in textbox   the result show  0  and  the userform contains textbox1,2   the result shows in textbox3 after sum textbox1,2  and this  is  what happend in my programm 


you note my result in textbox3 =0.00 it  have to be 3,005.00 

and this is my codes 

Private Sub CommandButton1_Click()

TextBox3.Value = Val(TextBox1) + Val(TextBox2)

End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Text = Format(TextBox1.Text, "$#,##0.00")
End Sub

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Text = Format(TextBox2.Text, "$#,##0.00")
End Sub

Private Sub TextBox3_Change()
TextBox3.Text = Format(TextBox3.Text, "$#,##0.00")
End Sub


2 Answers

+1 vote
by Skilled (749 points)
selected by
Best answer

Most of the questions here refer to Excel VBA, but perhaps you are not using your form with Excel. Will this work for you?

S1 = Replace(TextBox1.Text, "$", "")
S1 = Replace(S1, ",", "")
S2 = Replace(TextBox2.Text, "$", "")
S2 = Replace(S2, ",", "")
TextBox3.Value = Val(S1) + Val(S2)


by Beginner (48 points)
it gives me value of textbox1 and ignore value of textbox2  it's dissapointed
by Beginner (48 points)

this is my file you can check it  


by Skilled (749 points)
Sorry. I was in a hurry earlier, but now I've edited my 2nd answer. Will that work?
by Beginner (48 points)
i 'm so sorry about this  it gives me in textbox3= 0.00

i hope when you have free tim you see my file it possible know where is the problem
by Skilled (749 points)
I made another edit. Does that work?
by Beginner (48 points)
thanks so much  finally  it really works
0 votes
by Skilled (749 points)
edited by

Try this:

TextBox3.Value = Application.WorksheetFunction.Value(TextBox1.Value) + Application.WorksheetFunction.Value(TextBox2.Value)

"The Val function stops reading the string at the first character that it can't recognize as part of a number. Symbols and characters that are often considered parts of numeric values, such as dollar signs and commas, are not recognized."

by Beginner (48 points)
thanks buddy  but  it doesn't work  it gives me the same result  0.00
by Skilled (749 points)

See my edited answer above.

by Beginner (48 points)

sorry buddy it gives me error 



by Skilled (749 points)
Sorry. I've edited my answer again. If that doesn't work, I give up.
by Beginner (48 points)
unfortunatly  it doesn't  work  i appreciate  your efforts   and i'm for wating sombody help

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.


For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.