How to Change Text Color with Formula in Excel (2 Methods)

We have some book names and their online prices for two consecutive years. We’ll change the color of the prices with the formula.


Method 1 – Formula with Conditional Formatting to Change Text Color in Excel

Case 1.1 – Use Highlight Cells Rules

Steps:

  • Select the data range C5:D12.
  • Go to Home, then select Conditional Formatting and choose Highlight Cells Rules.
  • You will get 4 options: Greater Than, Less Than, Between, and Equal To.
  • Select which one you need.

Steps for Greater Than:

  • Select your desired range in Format cells that are GREATER THAN box.
  • We have set the value at $120. Excel will change the color of the text and highlight only those values that are greater than $120.
  • Select your desired color.
  • Press OK.

Steps for Greater Than option:

  • Here are the results.

Steps for Greater Than option:

Steps for Less Than:

  • We have set the less than the value at $110. That means it will change the color of the text and highlight only those values that are less than $110.
  • Select your desired color.
  • Press OK.

Steps for Less Than option:

  • Here are the results.

Steps for Less Than option:

Steps for Between:

  • Set the start and end range values in their respective boxes.
  • Select your desired color.
  • Press OK.

Steps for Between option:

  • Here’s our output:

Steps for Between option:

Steps for Equal To:

  • Set the value in the Format cells that are EQUAL TO box.
  • Select a color.
  • Press OK.

Steps for Equal To option:

  • Here are the results.

Steps for Equal To option:


Case 1.2 – Apply New Rule

We’ll change the text color of those rows if the values in Column C are greater than Column D.

Steps:

  • Select the data range C5:D12.
  • Go to Conditional Formatting and choose New Rule.
  • A dialog box will appear.

New Rule

  • Select Use a formula to determine which cells to format under Select a Rule Type.
  • Use the formula given below in Format values where this formula is true box.

New Rule

  • Press Format. Another dialog box will open up.
  • Set your desired color from the Color box of the Font option. You can also choose a Fill color instead from the Fill tab.
  • Press OK.

New Rule

  • Press OK again.

New Rule

  • Here’s our output with the picked text color.


Method 2 – Using VBA Macros to Change Text Color in Excel

Steps:

  • Right-click on the sheet title.
  • Select View Code from the context menu.
  • A VBA window will open up.

VBA Macros to Change Text Color in Excel

  • Insert the code given below:
Function TextColor(n1 As Double, n2 As Double) As Boolean
    If n1 <= n2 Then
        Application.Caller.Font.ColorIndex = 3
    Else
        ' Set font to normal
        Application.Caller.Font.ColorIndex = xlAutomatic
    End If
End Function
Sub Tcolor()
End Sub
  • Press the Run icon. You’ll get a new dialog box to create a macro.

VBA Macros to Change Text Color in Excel

  • Give the macro a name.
  • Press Create.

VBA Macros to Change Text Color in Excel

  • Press the Run icon again to run the codes.

VBA Macros to Change Text Color in Excel

  • Insert the following formula in Cell D14:
=IF(C5>D5,1,0)+TextColor(C5,D5)
  • Hit the Enter button.

VBA Macros to Change Text Color in Excel

  • Here’s the result.


Download the Practice Book


Related Articles


<< Go Back to Color Cell in Excel | Excel Cell Format | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Md. Sourov Hossain Mithun
Md. Sourov Hossain Mithun

Md. Sourov Hossain Mithun, an Excel and VBA Content Developer at Softeko's ExcelDemy project, joined in October 2021. Holding a Naval Architecture & Marine Engineering degree from BUET, Mithun showcases expertise during his two-year tenure. With over 200 published articles on Excel topics, he earned a promotion to Team Leader, excelling in leading diverse teams. Mithun's passion extends to Advanced Excel, Excel VBA, Data Analysis, and Python programming, contributing significantly to the innovative and dynamic environment of ExcelDemy... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo