Text Box Calculation

  • Thread starter Thread starter Marcus
  • Start date Start date
M

Marcus

I am sure this should be easy :

I am trying to get excel to do a calculation via textboxes.

For example

If textbox1.value > textbox2.value then
Textbox1.forecolor = "red"
else
Textbox1.forecolor = "green"
end if

It maybe a little more complex because my values are in
date format. i.e. textbox1 = "01 jan 2003" textbox2 = "01
jan 2004"

Many thanks in advance

MArcus
 
hi,
tested. it work
Private Sub Text11_BeforeUpdate(Cancel As Integer)
If Me.Text9.Value > Me.Text11.Value Then
Me.Text9.ForeColor = RGB(255, 7, 64) 'red
Else
Me.Text9.ForeColor = RGB(7, 183, 20) 'green
End If
End Sub

Private Sub Text9_BeforeUpdate(Cancel As Integer)
If Me.Text9.Value > Me.Text11.Value Then
Me.Text9.ForeColor = RGB(255, 7, 64) 'red
Else
Me.Text9.ForeColor = RGB(7, 183, 20) 'green
End If

End Sub
 
hi again.
forget the last post. i forgot where i was at and did that
for access. sorry
here is excel
Private Sub TextBox1_Change()
If Me.TextBox1.Value > Me.TextBox2.Value Then
Me.TextBox1.ForeColor = RGB(255, 7, 64) 'red
Else
Me.TextBox1.ForeColor = RGB(7, 183, 20) 'green
End If
End Sub

Private Sub TextBox2_Change()
If Me.TextBox1.Value > Me.TextBox2.Value Then
Me.TextBox1.ForeColor = RGB(255, 7, 64) 'red
Else
Me.TextBox1.ForeColor = RGB(7, 183, 20) 'green
End If
End Sub
 
Just note that your doing a string compare which may or may not work.

I suggest you do

Private Sub TextBox1_Change()
If cDate(Me.TextBox1.Value) > cDate(Me.TextBox2.Value) Then
Me.TextBox1.ForeColor = RGB(255, 7, 64) 'red
Else
Me.TextBox1.ForeColor = RGB(7, 183, 20) 'green
End If
End Sub
 
.... and this works? Or not.
Geof.
-----Original Message-----
hi again.
forget the last post. i forgot where i was at and did that
for access. sorry
here is excel
Private Sub TextBox1_Change()
If Me.TextBox1.Value > Me.TextBox2.Value Then
Me.TextBox1.ForeColor = RGB(255, 7, 64) 'red
Else
Me.TextBox1.ForeColor = RGB(7, 183, 20) 'green
End If
End Sub

Private Sub TextBox2_Change()
If Me.TextBox1.Value > Me.TextBox2.Value Then
Me.TextBox1.ForeColor = RGB(255, 7, 64) 'red
Else
Me.TextBox1.ForeColor = RGB(7, 183, 20) 'green
End If
End Sub
.
 
Many thanks all I think it works although sometimes the
textbox does automatically change when date is entered.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top