Selected Answer
Hi jdgrapes (Joseph?) and good evening (from here)!
Your question doesn't say which procedure you had trouble with but I think the answer is the same. Textboxes store strings (even in the Value property) so you need to convert them to an appropriate data type.
For example, you have a procedure in your UserForm as follows:
Private Sub txtTTl02_Change()
Me.txtTTL02.Value = Val(Me.txtTrgt3.Value) - Val(Me.txtTTL01.Value)
End Sub
but the Val function doesn't exist in VBA (unless you define it).
I suggest you use a VBA conversion function like Cdbl (which can convert a number-like string into a Double value which can be manipulated arithmetically). That would change the above code to read:
Private Sub txtTTl02_Change()
Me.txtTTL02.Value = CDbl(Me.txtTrgt3.Value) - CDbl(Me.txtTTL01.Value)
End Sub
and the control txtTTL02 would show the result of the subtraction.
The Microsoft guidance on various datatype conversions is here: [LINK URL="learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/type-conversion-functions"]Type conversion functions[/LINK]
Revision 26 March 2024
The attached revisied file has an orange button "Add textboxes demo". Click that and a new userform appears. Type two number is the left hand text boxes then click the green button- that runs this code:
Private Sub Cb_Add_Click()
' check text can be converted to numbers
If Not IsNumeric(TextBox1) Or Not IsNumeric(TextBox1) Then Exit Sub
' convert to Double data type and add values
TextBox3.Value = CDbl(TextBox1.Value) + CDbl(TextBox2.Value)
' format to fix 2 decimal places
TextBox3.Text = Format(TextBox3.Value, "#,##0.00")
End Sub
The result (to 2 dps) will be in the textbox below the green button.
Hope this helps and you can apply to your problem- if so, please be sure to mark this Answer as Selected. If not, please clarify your original question.
p.s. Next time, please try to be more specific when asking a question- you're more likely to get a better answer. Also, kindly edit your original question to correct the spelling of Subtraction in the title- that will help others