Hello Gal403,
The code shown for the UserForm has been tested. Delete any code in the UserForm and paste this code in it's place.
UserForm Code
Dim CurrentSum As Double
Dim InitialValue As Double
Function ZeroValueCheck(ByRef Ctrl As Control) As Boolean
Dim CurrentSum As Double
Dim n As Double
CurrentSum = Val(TextBox2.Value) + Val(TextBox3.Value) + Val(TextBox4.Value)
n = InitialValue - CurrentSum
If n < 0 Then
MsgBox "The Subtraction Result will be Less Than Zero with this value.", vbExclamation
CurrentSum = CurrentSum - Val(Ctrl.Value)
Ctrl.Value = 0
Ctrl.SelStart = 0
Ctrl.SelLength = 1
ZeroValueCheck = True
Else
TextBox1.Value = n
End If
End Function
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = ZeroValueCheck(TextBox2)
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = ZeroValueCheck(TextBox3)
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = ZeroValueCheck(TextBox4)
End Sub
Private Sub UserForm_Initialize()
InitialValue = Val(TextBox1.Value)
End Sub
Bookmarks