I am creating a form in which I have a set range of values. I would like to change the text color if the value is out of my set range. How do I write this IF formula?
Change font color based on cell value
-
-
-
Re: Writing an "IF" formula change text color
This should get you started. Place it in the worksheet modual.
Code
Display MoreRange("A1:A15").Select 'Edit what range this condition applys to EG A1:A5 ect Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _ Formula1:="=2" 'Change this value the number you want to be equal to or less than Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Font .Color = -16776961 ' Color is Red .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False End
Its a conditional format macro. Im new to VBA also and just thought i would try and help. :smile: -
Re: Writing an "IF" formula change text color
Perhaps using conditional formating is more direct.
You can read all about it at
http://www.ozgrid.com/Excel/conditional-formatting.htm
Yura -
Re: Change font color based on cell value
Hello lsmoove,
Welcome to Ozgrid.
Thread titles are important for obtaining good search results and should be written with this thought in mind -- that is, the title should be "search friendly", meaning a search using YOUR title as the search terms will yield relevant results. Thread titles should concisley and accurately describe the content of your thread.
Note the change in your title, based on your overall thread content, as an example when creating future threads.
What kind of "form" are you using? Is this a custom User Form with VBA code or is this a worksheet "form". If the latter, then use the built in conditional formatting. If you are using a customer User Form, then see the link provided in previous post.
-
Re: Change font color based on cell value
Thank you I will give it a shot.
-
Re: Change font color based on cell value
YagerBoy Thanks for the Code, but it didn't work, any other suggestions?
-
Re: Change font color based on cell value
Take a look at the link YuraYong provided. I believe that will be your best shot. The code i provided was a recording of setting a conditional format. HTH
Is your data on a worksheet or a userform?
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!