Sum textboxes on a userform in a textbox

Racquet

Board Regular
Joined
Feb 3, 2006
Messages
80
I have 3 text boxes on a user form, titled txt1, txt2, txt3. The first two textboxes are to be used for entry of a number. The third text box needs to automatically reflect the sum of the first two text boxes whenever an entry is made in either text box or the original entry is updated. I have code to prevent entry of a non numeric entry (and a message to tell the user that the entry must be numeric). However, I cannot get the third box to reflect a total . The result that I am obtaining now is an entry of 4 in txt1 and 5 in txt 3 displays as $4$5 in txt3. Hopefully there is a very simple solution to this question. The code is as follows:

VBA Code:
Private Sub txt1_Change()
 
    Txt1.BackColor = vbWhite
    If Not IsNumeric(Txt1.Value) Then
        Txt1.Value = ""
        Txt1.BackColor = vbYellow
        MsgBox ("This entry must be a positive whole number!")
        Me.Txt1.Value = 0
    Else
        Me.Txt1.Value = Format(Me.Txt1.Value, "$#,##0")
    End If
    Txt3.Value = Format((Txt1.Value) + (Txt2.Value), "$#,##0")
     
End Sub

Private Sub txt2_Change()

Txt2.BackColor = vbWhite
   If Not IsNumeric(Txt2.Value) Then
        Txt2.Value = ""
        Txt2.BackColor = vbYellow
        MsgBox ("This entry must be a positive whole number!")
        Me.Txt2.Value = 0
    Else
        Me.Txt2.Value = Format(Me.Txt2.Value, "$#,##0")
    End If
      Txt3.Value = Format((Txt1.Value) + (Txt2.Value), "$#,##0")

End Sub
 
Last edited by a moderator:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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