![]() |
Text format - setting text colour with code
I'm on the home straight now (I think). What I would like to do is make text
in a text box go red if a certain condition is met. ie. If rider1.value 700 Then rider1.font = colour red (or whatever the correct code for this is) Thanks |
Text format - setting text colour with code
If rider1 700 Then
rider1.Font.ColorIndex = 3 Else rider1.Font.ColorIndex = xlAutomatic End If But you can accomplish the same thing using conditional formatting, without any code at all. Format -- Cells --Conditional Format Then set up for cell value 700 and set the font color. "NDBC" wrote: I'm on the home straight now (I think). What I would like to do is make text in a text box go red if a certain condition is met. ie. If rider1.value 700 Then rider1.font = colour red (or whatever the correct code for this is) Thanks |
Text format - setting text colour with code
Thanks for the reply. Does conditional formatting work in text boxes on user
forms. "JLatham" wrote: If rider1 700 Then rider1.Font.ColorIndex = 3 Else rider1.Font.ColorIndex = xlAutomatic End If But you can accomplish the same thing using conditional formatting, without any code at all. Format -- Cells --Conditional Format Then set up for cell value 700 and set the font color. "NDBC" wrote: I'm on the home straight now (I think). What I would like to do is make text in a text box go red if a certain condition is met. ie. If rider1.value 700 Then rider1.font = colour red (or whatever the correct code for this is) Thanks |
Text format - setting text colour with code
JL
Just tried that and am getting an error. I clicked on the textbox object and the name is rider1 (Rider1 TextBox at top). I want the text in this box to be red based on the value of the text/number entered in the box. I think I must be refering to the textbox incorrectly. Any ideas. "JLatham" wrote: If rider1 700 Then rider1.Font.ColorIndex = 3 Else rider1.Font.ColorIndex = xlAutomatic End If But you can accomplish the same thing using conditional formatting, without any code at all. Format -- Cells --Conditional Format Then set up for cell value 700 and set the font color. "NDBC" wrote: I'm on the home straight now (I think). What I would like to do is make text in a text box go red if a certain condition is met. ie. If rider1.value 700 Then rider1.font = colour red (or whatever the correct code for this is) Thanks |
Text format - setting text colour with code
Nope, that code won't work with a textbox - it works with a cell. I didn't
realize we were talking about text boxes, since textboxes don't have numeric values that you can test, they contain text/words/numers that are text and not really numbers. I've got to rush off right now, but I'll work up something for the textbox shortly - where did the textbox come from? The "Controls Toolbox" group or the "Forms" group. "NDBC" wrote: JL Just tried that and am getting an error. I clicked on the textbox object and the name is rider1 (Rider1 TextBox at top). I want the text in this box to be red based on the value of the text/number entered in the box. I think I must be refering to the textbox incorrectly. Any ideas. "JLatham" wrote: If rider1 700 Then rider1.Font.ColorIndex = 3 Else rider1.Font.ColorIndex = xlAutomatic End If But you can accomplish the same thing using conditional formatting, without any code at all. Format -- Cells --Conditional Format Then set up for cell value 700 and set the font color. "NDBC" wrote: I'm on the home straight now (I think). What I would like to do is make text in a text box go red if a certain condition is met. ie. If rider1.value 700 Then rider1.font = colour red (or whatever the correct code for this is) Thanks |
Text format - setting text colour with code
Try
Me.TextBox1.ForeColor = vbRed If this post helps click Yes --------------- Jacob Skaria "NDBC" wrote: JL Just tried that and am getting an error. I clicked on the textbox object and the name is rider1 (Rider1 TextBox at top). I want the text in this box to be red based on the value of the text/number entered in the box. I think I must be refering to the textbox incorrectly. Any ideas. "JLatham" wrote: If rider1 700 Then rider1.Font.ColorIndex = 3 Else rider1.Font.ColorIndex = xlAutomatic End If But you can accomplish the same thing using conditional formatting, without any code at all. Format -- Cells --Conditional Format Then set up for cell value 700 and set the font color. "NDBC" wrote: I'm on the home straight now (I think). What I would like to do is make text in a text box go red if a certain condition is met. ie. If rider1.value 700 Then rider1.font = colour red (or whatever the correct code for this is) Thanks |
Text format - setting text colour with code
Thank you, it worked without the me. at the start.
"Jacob Skaria" wrote: Try Me.TextBox1.ForeColor = vbRed If this post helps click Yes --------------- Jacob Skaria "NDBC" wrote: JL Just tried that and am getting an error. I clicked on the textbox object and the name is rider1 (Rider1 TextBox at top). I want the text in this box to be red based on the value of the text/number entered in the box. I think I must be refering to the textbox incorrectly. Any ideas. "JLatham" wrote: If rider1 700 Then rider1.Font.ColorIndex = 3 Else rider1.Font.ColorIndex = xlAutomatic End If But you can accomplish the same thing using conditional formatting, without any code at all. Format -- Cells --Conditional Format Then set up for cell value 700 and set the font color. "NDBC" wrote: I'm on the home straight now (I think). What I would like to do is make text in a text box go red if a certain condition is met. ie. If rider1.value 700 Then rider1.font = colour red (or whatever the correct code for this is) Thanks |
All times are GMT +1. The time now is 03:01 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com