Change Font Color Based on Value of Another Cell in Excel

In this tutorial, we will demonstrate how to change font color based on the value of another cell. Here is an overview of the process.

Overview of Changing Font Color Based on Value of Another Cell in Excel


To demonstrate this tutorial, we’ll use this dataset:

Showing Dataset

Our goal is to find the students who failed (scoring less than 33) and change the font color for those rows.

Method 1 – Using Conditional Formatting

Steps:

  •  Add a criteria table like the image below.

Adding Criteria Table to Change Font Color Based on Value of Another Cell in Excel

  • Select the range of cells B5:D12.

Selecting Data Range to Change Font Color Based on Value of Another Cell in Excel

  • From the Home tab, select Conditional Formatting >> New Rule.

Selecting New Rules to Change Font Color Based on Value of Another Cell in Excel

  • From the New Formatting Rule dialog box, select Use a formula to determine which cells to format.

Choosing Rule Type to Change Font Color Based on Value of Another Cell in Excel

  •  Enter the following formula in the field:
=$D5<$F$5
  • Click on Format.

Inserting Condition in Conditional Formatting to Change Font Color Based on Value of Another Cell in Excel

  • From the Format Cells dialog box, select the Font tab.
  • Choose any color from the dropdown menu.
  • Click on OK.

Setting Font Color to Change Font Color Based on Value of Another Cell in Excel

  • Click OK again.

Steps for Conditional Formatting

The font color of the rows containing the students who failed changes to red.

Result Output by Conditional Formatting


Method 2 – Using VBA Code

In this method, we’ll use conditional formatting on one row, then use a VBA macro to repeat across our dataset.

Steps:

  • Select the range of cells B5:D5.

Selecting First Row

  • From the Home tab, select Conditional Formatting > New Rule.

Setting New Rules

  • From the New Formatting Rule dialog box, select Use a formula to determine which cells to format.

Choosing Rule Type

  • Enter the following formula in the field:
=$D5<$F$5
  • Click on Format.

Setting Condition for Conditional Formatting

  • From the Format Cells dialog box select the Font option.
  • Choose any color from the dropdown menu.
  • Click on OK.

Setting Font and Color

  • Click OK again.

The first row is formatted. Let’s copy it across all the rows.

Steps for Conditional Formatting

  • Press Alt+F11 on your keyboard to open the VBA Editor.
  • Click on Insert > Module. 
  • Enter the following code in the module window:
Sub format_all_rows()
Dim rng As Range
Dim r As Long
Set rng = Selection
rng.Rows(1).Copy
For r = 2 To rng.Rows.Count
 rng.Rows(r).PasteSpecial Paste:=xlPasteFormats
Next r
End Sub
  • Save the file.

Inserting VBA Code in Macro

  • Select the range of cells B5:D12.

Selecting Data Range

  • Press Alt+F8 to open the Macro dialog box.
  • Select the macro format_all_rows.
  • Click on Run.

Running VBA Code

All the students with Marks less than 33 appear in color fonts.

Using VBA Code to Change Font Color Based on Value of Another Cell in Excel

Read More: VBA Conditional Formatting Based on Another Cell Value in Excel


Things to Remember

The VBA macro is just to copy the formats. It will individually create that formula for every row. If your dataset is large, this may take some time, but not as much as doing it manually!


Download the Practice Workbook


Related Articles

<< Go Back to Conditional Formatting with Multiple Conditions | Conditional Formatting | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
A.N.M. Mohaimen Shanto
A.N.M. Mohaimen Shanto

A.N.M. Mohaimen Shanto, a B.Sc. in Computer Science and Engineering from Daffodil International University, boasts two years of experience as a Project Manager at Exceldemy. He authored 90+ articles and led teams as a Team Leader, meticulously reviewing over a thousand articles. Currently, he focuses on enhancing article quality. His passion lies in Excel VBA, Data Science, and SEO, where he enjoys simplifying complex ideas to facilitate learning and growth. His journey mirrors Exceldemy's dedication to excellence and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo