0 votes
in VBA by Beginner (58 points)

hello

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 Expert (805 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 (58 points)
it gives me value of textbox1 and ignore value of textbox2  it's dissapointed
by Beginner (58 points)

this is my file you can check it  

https://ufile.io/nktl80xm

by Expert (805 points)
Sorry. I was in a hurry earlier, but now I've edited my 2nd answer. Will that work?
by Beginner (58 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 Expert (805 points)
I made another edit. Does that work?
by Beginner (58 points)
thanks so much  finally  it really works
0 votes
by Expert (805 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 (58 points)
thanks buddy  but  it doesn't work  it gives me the same result  0.00
by Expert (805 points)

See my edited answer above.

by Beginner (58 points)

sorry buddy it gives me error 

 

 

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

Welcome to wellsr Q&A
Ask any questions you have about VBA and Python and our community will help answer them. wellsr Q&A is the standalone question and answer platform for wellsr.com. If you have a question about one of our specific tutorials, please include a link back to the tutorial.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Looking for something else? Hire our team directly through ourVBA Help page, instead.

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

...