Change the font color if the value exceeds the specfifcation

Shi6oonz

New Member
Joined
Jul 15, 2018
Messages
16
Hello all

i am using this code to change the font color to red color if ( Textbox3.value < textbox22.value ) see the code below please ...

Code:
Private Sub TextBox3_Change()
If TextBox3.Value < TextBox22.Value Then
        TextBox3.ForeColor = RGB(0, 0, 0)
    Else
        TextBox3.ForeColor = RGB(255, 0, 0)
    End If
End Sub

the value of Textbox22 is "200" , if i enter value of "39" in Textbox3 the red color will present also !
that means the value of textbox22 is "2" not "200"

any help ? please

thanls
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
How about
Code:
Private Sub TextBox3_AfterUpdate()
If Val(TextBox3.Value) < Val(TextBox22.Value) Then
        TextBox3.ForeColor = RGB(0, 0, 0)
    Else
        TextBox3.ForeColor = RGB(255, 0, 0)
    End If
End Sub
 
Upvote 0
How about
Code:
Private Sub TextBox3_AfterUpdate()
If Val(TextBox3.Value) < Val(TextBox22.Value) Then
        TextBox3.ForeColor = RGB(0, 0, 0)
    Else
        TextBox3.ForeColor = RGB(255, 0, 0)
    End If
End Sub
:eeek:
Thank you So Much i really appreciated
work like a charm !
 
Upvote 0
You're welcome & thanks for the feedback.

Val converts the textbox value (which is a string) into a number.
 
Upvote 0

Forum statistics

Threads
1,225,635
Messages
6,186,128
Members
453,340
Latest member
Stu61

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