Userform Textbox conditional formatting

rmak85

New Member
Joined
Oct 3, 2018
Messages
12
Hello,
Im trying to get the text box to go red if the value is over 318 and green if under.
This code works if I put the value directly into the code.
Code:
Private Sub TextBox24_Change()
If Textbox3.Text = "Cathode Mother Roll" And TextBox24.Value > "318" Then TextBox24.BackColor = RGB(255, 0, 0) 'Red
If Textbox3.Text = "Cathode Mother Roll" And TextBox24.Value <= "318" Then TextBox24.BackColor = RGB(0, 255, 0) 'Green

If Textbox3.Text = "Cathode Mother Roll" And TextBox24.Text = "-" Then TextBox24.BackColor = RGB(255, 255, 255) 'White

End Sub


But I want the value to be based of the value in a cell in another worksheet. But the following code does not work and changes the textbox to red whatever the number i put in the box


Code:
Private Sub TextBox24_Change()

If Textbox3.Text = "Cathode Mother Roll" And TextBox24.Value > [Specs!F28].value Then TextBox24.BackColor = RGB(255, 0, 0) 'Red
If Textbox3.Text = "Cathode Mother Roll" And TextBox24.Value <= [specs!F28].value Then TextBox24.BackColor = RGB(0, 255, 0) 'Green

If Textbox3.Text = "Cathode Mother Roll" And TextBox24.Text = "-" Then TextBox24.BackColor = RGB(255, 255, 255) 'White

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The values in a textbox are text, if you want to compare them with numerical values you need to convert them.
Code:
Private Sub TextBox24_Change()

    If Textbox3.Text = "Cathode Mother Roll" And Val(TextBox24.Value) > [Specs!F28].value Then TextBox24.BackColor = RGB(255, 0, 0) 'Red

    If Textbox3.Text = "Cathode Mother Roll" And Val(TextBox24.Value) <= [specs!F28].value Then TextBox24.BackColor = RGB(0, 255, 0) 'Green

    If Textbox3.Text = "Cathode Mother Roll" And TextBox24.Value = "-" Then TextBox24.BackColor = RGB(255, 255, 255) 'White

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,757
Messages
6,126,695
Members
449,331
Latest member
smckenzie2016

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