If I enter $42.87 in textbox1, how can I restrict the value in textbox 2 to not exceed the vaue in textbox1?
Thank you
If I enter $42.87 in textbox1, how can I restrict the value in textbox 2 to not exceed the vaue in textbox1?
Thank you
Perhaps something like
[VBA]Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox1
.Text = Format(NumFromCur(.Text), "$#.00")
If NumFromCur(.Text) < NumFromCur(TextBox2.Text) Then
TextBox2.Text = vbNullString
End If
End With
End Sub
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox2
.Text = Format(NumFromCur(.Text), "$#.00")
Cancel = NumFromCur(TextBox1.Text) < NumFromCur(TextBox2.Text)
If Cancel Then
MsgBox "TextBox2 must not exceed TextBox1"
.SelStart = 0
.SelLength = Len(.Text)
End If
End With
End Sub
Function NumFromCur(aString As String) As Double
NumFromCur = Val(Replace(aString, "$", vbNullString))
End Function
[/VBA]
Thank you Mike. Works like a charm!