User Form Addition

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Hello All
Code:
Private Sub Btn_Find_Budget_Click()
On Error GoTo Error_Handler

If (Tbx_REV = vbNullString) Or (Tbx_Actual = vbNullString) Then
    MsgBox ("To Compute Budget:" _
    & vbNewLine & "REV & Actual fields require an input")
    Exit Sub
End If
Tbx_Budget = (Tbx_REV + Tbx_Actual)
Error_Handler:
MsgBox "Test"

I'm not understanding something here...
I have:
Tbx_Actual = (Tbx_Budget - Tbx_REV)

&

Tbx_Budget = (Tbx_REV + Tbx_Actual)

The subtraction in the Tbx_Actual works correctly. However, the Tbx_Budget combines the two numbers instead of summing them.
If I have Tbx_REV = 2 and I have Tbx_Actual =4. The output in Tbx_Budget = 24, instead of 6.

Why is this? How do I sum Tbx_REV and Tbx_Actual?

Thanks for the help
excel 2013
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
If your numbers are whole numbers try
Code:
    Tbx_Budget = CLng(Tbx_REV) + CLng(Tbx_Actual)
As the values in a textbox are text the + concatentates the two text values.
if you convert them into numbers then they will be summed

If you are using decimals change Clng to Cdbl
 
Last edited:
Upvote 0
Try this.
Code:
Tbx_Budget.Value = Val(Tbx_REV.Value) + Val(Tbx_Actual.Value)
Or this.
Code:
Dim Res As Variant

    ' other code

    Res = Evaluate(Tbx_REV & "+" & Tbx_Actual)

    Tbx_Budget = Iif(IsError(Res),"Error", Res)
 
Upvote 0
Code:
As the values in a textbox are text the + concatentates the two text values.
 if you convert them into numbers then they will be summed

This is what I thought, theproblem is I don't know the syntax from vbNullString for numbers instead of string text...
What can I use instead of vbNullString?
Thanks
 
Upvote 0
Not sure what you mean.
Have you tried my solution, or either of Norie's?
 
Upvote 0
Yes, and they both work
If I use vbNullString, Isn't excel looking for a cell with no text? What would be the code for a excel to look for a cell with numbers only? Would it be something similar to vbNullValue?
 
Upvote 0
For that you need IsNumeric()
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top