Conditional Formatting a text box

StewartS

Board Regular
Joined
Feb 24, 2002
Messages
217
I have a text box on a chart which is linked to a cell on a sheet which has a 1,2 or 3 in it. Is there any way I can set the formatting in the text box so that the background is a specific colour depending on the number in the linked cell.

Thanks in advance

StewartS
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hello Stewart. You can use a change event to set the background color, like:<pre>
Private Sub TextBox1_Change()
If TextBox1.Value = "" Or Not "1" Or Not "2" Or Not "3" Then _
TextBox1.BackColor = RGB(0, 0, 0)
If TextBox1.Value = "1" Then TextBox1.BackColor = RGB(255, 0, 0)
If TextBox1.Value = "2" Then TextBox1.BackColor = RGB(0, 255, 0)
If TextBox1.Value = "3" Then TextBox1.BackColor = RGB(0, 0, 255)
End Sub</pre>

Right click on your textbox and select view code (design mode). Paste the code in and modify the name of textbox1 to your actual name. Play with the colors as desired.

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-06-24 07:55
 
Upvote 0
Hi - this worked perfectly on an Excel 2003 spreadsheet I 'm working on.

My question is: Is there any way to edit the code above to apply the formatting to all text boxes on a worksheet rather than a specific one?

Thanks
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

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