Conditional Formatting Based on Formula – Excel & Google Sheets

Written by

Editorial Team

Reviewed by

Laura Tsitlidze

Last updated on July 3, 2022

This tutorial demonstrates how to apply conditional formatting based on a formula in Excel and Google Sheets.

 

formulas cond format intro pic

 

Conditional Formatting in Excel comes with plenty of preset rules to enable you to quickly format cells according to their content. These preset rules do, however, have limitations, which is where using a formula to determine the format of a cell comes into play. This gives you much greater flexibility over your conditional formatting.

Conditional Formatting Formula Rules

Equal To

  1. Highlight the cells where you want to set the conditional formatting and then, in the Ribbon, select Home > Conditional Formatting > New Rule.

 

formulas cond format equalto before

 

  1. Select Use a formula to determine which cells to format, and enter the formula:
    =$C4=”Western”

 

formulas cond format new rule

 

You always need to start your formula with an equal sign.

The formula tests whether the result is TRUE or FALSE much like the traditional Excel IF statement, but in the case of conditional formatting, you do not need to add the true and false conditions. If the formula returns TRUE, then formatting you set in the Format part of the rule is applied to the relevant cells.

You need to use a mixed reference in this formula ($C4) in order to lock the column (make it absolute) but make the row relative. This enables the formatting to format the entire row instead of just a single cell that meets the criteria.

When the rule is evaluated for all the cells in the range, the row changes, but the column does not. This causes the rule to ignore the values in any of the other columns and just concentrate on the values in Column C. If Column C of that row contains the word Western, the formula result is TRUE, and the formatting is applied for the whole row.

  1. Click Format… and select your desired formatting.

 

formulas cond format format

 

  1. Click OK and then OK again to view the result.

 

formulas cond format equalto result

 

The rows where Column C is Western are highlighted, while other rows are not. In the example above, just two rows end up highlighted.

Not Equal

If you want to create an opposite rule, you can use the <> (not equal to) operator instead of =.

=$C4<>”Western”

 

formulas-cond format not equal to

 

This results in the opposite: Most of the rows are now highlighted!

 

formulas cond format not equalto result

 

Greater Than

You can also test for greater than using a formula. For example, you can use a formula to check if the values in Column D are greater than $23,000.

=$D4>23000

formulasgreaterthan

 

This rule highlights only rows where the value in Column D is greater than $23,000.

 

formulasgreaterthan result

 

Greater Than or Equal To

Similarly, you could highlight the rows where the value in Column D is greater than or equal to $23,000 with this formula below:

=$D4>=23000

 

formulasgreaterthanequalto

 

The result for this formula would be slightly different: Rows where the Red value is exactly $23,000 are also highlighted (here, Row 5).

 

formulasgreaterthanequalto result

 

Less Than

Swapping the > sign for a < sign tests for values that are less than $23,000.

=$D4<23000

 

formulas lessthan

 

Now only rows where Red is less than $23,000 are highlighted.

 

formulas lessthan result

 

Less Than or Equal To

To change the test to include the target value (e.g., $23,000), use <=.

=$D4<=23000

 

formulas lessthan equalto

 

Now, any rows in which Column D is equal to $23,000 are also highlighted.

 

formulas lessthan equalto result

 

Create Rules With OR, AND

OR Formula

You can create a more complicated rule by incorporating the Excel OR Function to expand the formula to look for two or more values.

  1. Enter the formula:
    =OR($C4=”Western”,$C4=”Eastern”)

 

formulas cond format or function

 

  1. Click on the Format… button and select your desired formatting, and then click OK to return to Excel.

This highlights all rows where the Region is Western or Eastern.

 

formulas cond format or function result

 

AND Formula

Similarly, you can create a rule using AND. This would mean checking the values in two or more columns.

 

formulas and

 

The formula above checks whether the text in Column C is Northern and the value in the corresponding row in Column D is greater than $23,000.

 

formulas and result

 

This conditional formatting rule highlights only the rows where both conditions are met.

IF Formula

You do not necessarily have to add an IF statement to the formula when you are creating it in a conditional formatting rule as the conditional formatting is always going to apply the rule if the formula that you have created returns a true value.

So, for example, this formula:

=IF($C4=”Western”,TRUE,FALSE)

and this formula

$C4=”Western”

both apply the same conditional formatting to your worksheet.

Built-in Excel Functions

Many built-in Excel functions can be used in conditional formatting such as ISBLANK, ISERROR, ISEVEN, ISNUMBER, etc.

ISBLANK Function

You can use the ISBLANK Function to create a rule to find rows that contain blank or empty cells in the worksheet.

  1. Highlight the range and then, in the Ribbon, select Home > Conditional Formatting > New Rule.
  2. Type in the formula:
    =ISBLANK($E3)

 

formulas cond format isblank

 

  1. Click on the Format… button and select your desired formatting and then click OK to return to Excel.

 

formulas-cond-format-isblank result

 

ISBLANK With OR

You can expand this to include blank cells or cells with an error in them.

  1. Type in the formula
    =OR(ISBLANK($E3),ISERROR($E3))

 

formulas cond format or blank error

 

  1. Click on the Format… button and select your desired formatting and then click OK to return to Excel.

 

formulas cond format or blank error

 

Other Functions in Conditional Formatting

There are a variety of other functions that can be used in creating conditional formatting formula-based rules.

For example, you can use the MAX Function to highlight the row that contains the maximum value in a specified column.

=$D4=MAX($D:$D)

 

formulas max

 

Now, only the row with the maximum value in Column D is highlighted.

 

formulas max result

 

If you are struggling to get a formula to work when creating a conditional formatting rule, it is a good idea to test the formula first in your Excel sheet. Once you have it right there, you can incorporate it in your rule.

Conditional Formatting Based on Formula in Google Sheets

Conditional Formatting works much the same in Google Sheets as it does in Excel.

  1. Highlight the cells where you want to set the conditional formatting and then, in the Menu, select Format > Conditional formatting.

 

formulas cond format gs intro

 

  1. Make sure the Apply to range is correct, and then select Custom formula is from the Format rules drop-down box. Type in the formula.

 

formulas cond format gs custom formula

 

  1. Then, select your formatting style and click Done.

 

formulas cond format gs formatted

 

You can also use greater than, greater than or equal to, less than, and less than or equal to in Google Sheets.

AND and OR also work, as well the other functions listed above for Excel (except for XLOOKUP, which does not exist in Google Sheets).

AI Formula Generator

Try for Free

See all How-To Articles