How to use color in if function in Excel

This tutorial will demonstrate how to highlight cells depending on the answer returned by an IF statement formula using Conditional Formatting in Excel and Google Sheets.

How to use color in if function in Excel

Highlight Cells With Conditional Formatting

A cell can be formatted by conditional formatting based on the value returned by an IF statement on your Excel worksheet.

  1. First, create the IF statement in Column E.
    =IF(D4>C4,”Overdue”,”Ontime”)

How to use color in if function in Excel

  1. This formula can be copied down to Row 12.
  2. Now, create a custom formula within the Conditional Formatting rule to set the background color of all the “Overdue” cells to red.
  3. Select the range you want to apply formatting to.
  4. In the Ribbon, select Home > Conditional Formatting > New Rule.

How to use color in if function in Excel

  1. Select Use a formula to determine which cells to format, and enter the formula:
    =E4=”OverDue”

How to use color in if function in Excel

  1. Click on the Format button and select your desired formatting.

How to use color in if function in Excel

  1. Click OK, and then OK once again to return to the Conditional Formatting Rules Manager.

How to use color in if function in Excel

  1. Click Apply to apply the formatting to your selected range and then click Close.
    The formula entered will return TRUE when the cell contains the word “Overdue” and will therefore format the text in those cells with a background color of red.
  2. To format the “OnTime” cells to green, you can create another rule based on the same range of cells.

How to use color in if function in Excel

  1. Click Apply to apply to the range.

How to use color in if function in Excel

Highlight Cells If… in Google Sheets

The process to highlight cells that contain an IF Statement in Google Sheets is similar to the process in Excel.

  1. Highlight the cells you wish to format, and then click on Format > Conditional Formatting.

How to use color in if function in Excel

  1. The Apply to Range section will already be filled in.

How to use color in if function in Excel

  1. From the Format Rules section, select Custom Formula and type in the formula.

How to use color in if function in Excel

  1. Select the fill style for the cells that meet the criteria.

How to use color in if function in Excel

  1. Click Done to apply the rule.

How to use color in if function in Excel

How do I color cells in Excel using if function?

Click the rule you'd like to apply to the selected cells to open a pop-up window containing a text box. Type a value in the “Format Cells” text box and click the drop-down menu next to that text box. That menu contains a list of colors such as “Yellow Fill with Dark Yellow Text” and “Red Border.”

Can you use if function with color?

Especially for huge MS Excel tables, it is helpful to mark cells with colors, if they contain a certain value. This is possible by using the “If-function”.