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: