Conditional formatting with formulas (2024)

Quick Links

  • Quick Start
  • Examples
  • Troubleshooting
  • Training

Conditional formatting is a fantastic way to quickly visualize data in a spreadsheet. With conditional formatting, you can do things like highlight dates in the next 30 days, flag data entry problems, highlight rows that contain top customers, show duplicates, and more.

Excel ships with a large number of "presets" that make it easy to create new rules without formulas. However, you can also create rules with your own custom formulas. By using your own formula, you take over the condition that triggers a ruleand can apply exactly the logic you need. Formulas give you maximum power and flexibility.

For example, using the "Equalto" preset, it's easy to highlight cells equal to "apple".

But what if you want to highlight cells equal to "apple" or "kiwi" or "lime"? Sure, you can create a rule for each value, but that's a lot of trouble.Instead, you can simply use one rule based on a formula with the OR function:

Conditional formatting with formulas (1)

Here's the result of the rule applied to the range B4:F8 in thisspreadsheet:

Conditional formatting with formulas (2)

Here's the exact formula used:

=OR(B4="apple",B4="kiwi",B4="lime")

Quick start

You can create a formula-based conditional formatting rule in four easy steps:

1. Select the cells you want to format.

Conditional formatting with formulas (3)

2. Create a conditional formatting rule, and select the Formula option

Conditional formatting with formulas (4)

3. Enter a formula that returns TRUE or FALSE.

Conditional formatting with formulas (5)

4. Set formatting options and save the rule.

Conditional formatting with formulas (6)

The ISODD function only returns TRUE for odd numbers, triggering the rule:

Conditional formatting with formulas (7)

Video: How to apply conditional formatting with a formula

We also offervideo training on conditional formatting.

Formula logic

Formulas that apply conditional formatting must return TRUE or FALSE, or numeric equivalents. Here are some examples:

=ISODD(A1)=ISNUMBER(A1)=A1>100=AND(A1>100,B1<50)=OR(F1="MN",F1="WI")

The above formulas all return TRUE or FALSE, so they work perfectly as a trigger for conditional formatting.

When conditional formatting is applied to a range of cells, enter cell references with respect to the upper-left cell.The trick to understanding how conditional formatting formulas work is to visualize the same formula being applied to each cell in the selection, with cell references updated as usual. Imagine that you entered theformula in the upper-left cell of the selection, and then copied the formula across the entire selection. If you struggle with this, see the section on Dummy Formulas below.

Formula Examples

Below are examples of custom formulas you can use to apply conditional formatting. Some of these examples can be created using Excel's built-in presets for highlighting cells, but custom formulas can go far beyond presets, as you can see below.

Also see: More than 30 Conditional Formatting Formulas

Highlight orders from Texas

To highlight rows that represent orders from Texas (abbreviated TX), use a formula that locks the reference to column F:

=$F5="TX"

Conditional formatting with formulas (8)

For more details, see this article: Highlight rows with conditional formatting.

Video: How to highlight rows with conditional formatting

Highlight dates in the next 30 days

To highlight dates occurring in the next 30 days, we need a formula that (1) makes sure dates are in the future and (2) makes sure dates are 30 days or less from today. One way to do this is to use the AND function together with the NOW function like this:

=AND(B4>NOW(),B4<=(NOW()+30))

With a current date of August 18, 2016, the conditional formatting highlightsdates as follows:

Conditional formatting with formulas (9)

The NOW function returns the current date and time. For details about how this formula, works, see this article: Highlight dates in the next N days.

Highlight column differences

Given two columns that contain similar information, you can use conditional formatting to spot subtledifferences. The formula used to trigger the formatting below is:

=$B4<>$C4

Conditional formatting with formulas (10)

See also: a version of this formula that uses the EXACT function to do a case-sensitive comparison.

Highlight missing values

To highlight values in one list that are missing from another, you can use a formula based on the COUNTIF function:

=COUNTIF(list,B5)=0

Conditional formatting with formulas (11)

This formula simply checks each value in List A against values in the named range "list" (D5:D10). When the count is zero, the formula returns TRUE and triggers the rule, which highlights values in List A that are missing from List B.

Video: How to find missing values with COUNTIF

Highlight properties with 3+ bedrooms under $350k

To find properties in this list that have at least 3 bedrooms but are less than $300,000, you can use a formula based on the AND function:

=AND($C5<350000,$D5>=3)

The dollar signs ($) lock the reference to columns C and D, and the AND function is used to make sure bothconditions are TRUE. In rows where the AND function returns TRUE, the conditional formatting is applied:

Conditional formatting with formulas (12)

Highlight top values (dynamic example)

Although Excel has presets for "top values", this example shows how to do the same thing with a formula, and how formulas can be more flexible. Byusing a formula, we can make the worksheet interactive— when the value in F2 is updated, the rule instantly responds and highlights new values.

Conditional formatting with formulas (13)

The formula used for this rule is:

=B4>=LARGE(data,input)

Where "data" is the named range B4:G11, and "input" is the named range F2. This page has details and a full explanation.

Gantt charts

Believe it or not, you can even use formulas to create simple Gantt charts with conditional formatting like this:

Conditional formatting with formulas (14)

This worksheet uses two rules, one for the bars, and one for the weekend shading:

=AND(D$4>=$B5,D$4<=$C5) // bars=WEEKDAY(D$4,2)>5 // weekends

This article explains the formula for bars, and this article explains the formula for weekend shading.

Simple search box

One cool trick you can do with conditional formatting is to build a simple search box. In this example, a rule highlights cells in column B that contain text typed in cell F2:

Conditional formatting with formulas (15)

The formula used is:

=ISNUMBER(SEARCH($F$2,B2))

For more details and a full explanation, see:

  • Article: How to highlight cells that contain specifictext
  • Article: How to highlight rows that contain specific text
  • Video: How to build a search box to highlight data

Troubleshooting

If you can't get your conditional formatting rules to fire correctly, there's most likely a problem with your formula. First, make sure you started the formula with an equals sign (=). If you forget this step, Excel will silently convert your entire formula to text, rendering it useless. To fix, just remove the double quotes Excel added at either side and make sure the formula begins with equals (=).

If your formulais entered correctlybut is not triggering the rule, you may have todig a little deeper. Normally, you can use the F9 key to check results in a formulaor use the Evaluate feature to step through a formula. Unfortunately, you can't use these tools with conditional formatting formulas, but you can use a technique called "dummy formulas".

Dummy Formulas

Dummy formulas are a way to test your conditional formatting formulas directly on the worksheet, so you can see what they're actually doing. This can be a big time-saver when you're struggling to get cell references working correctly.

In a nutshell, you enter the same formula across a range of cells that matches the shape of your data. This lets you see the values returned by each formula, and it's a great way to visualize and understand how formula-based conditional formatting works. For a detailed explanation, see this article.

Video: Test conditional formatting with dummy formulas

Limitations

There are some limitations that come with formula-based conditional formatting:

  1. You can't apply icons, color scales, or data bars with a custom formula. You are limited tostandard cell formatting, including number formats, font, fill color, and border options.
  2. You can't use certain formula constructs likeunions, intersections, or array constants for conditional formatting criteria.
  3. You can't reference other workbooks in a conditional formatting formula.

You can sometimes work around #2 and #3. You may be able to move the logic of the formula into a cell in the worksheet, and then refer to that cell in the formula instead. If you are trying to use an array constant, try creating a named range instead.

More CF formula resources

  • More than30conditional formatting formulas examples
  • Video training with practice worksheets
Conditional formatting with formulas (2024)

FAQs

Can you conditional format cells with formulas? ›

To control more precisely what cells will be formatted, you can use formulas to apply conditional formatting.

How to highlight cells with formulas in Excel? ›

Use the Ctrl + [ Shortcut: Another efficient way to highlight cells in a formula in Excel is to use the Ctrl + [ keyboard shortcut after selecting the cell with the formula to show cells used in a formula. This shortcut will immediately select all cells directly referenced by the formula in the active cell.

How do I add a custom formula in conditional formatting? ›

Use advanced conditional formatting
  1. On your computer, open a spreadsheet in Google Sheets.
  2. Select the cells you want to format.
  3. Click Format. Conditional formatting.
  4. Under the "Format cells if" drop-down menu, click Custom formula is. ...
  5. Click Value or formula and add the formula and rules.
  6. Click Done.

Why is my conditional formatting not working on a cell with a formula? ›

Conditional formatting rules that use formulas will only work if the formula returns a TRUE or FALSE value. To troubleshoot this, try simplifying the formula or using a different formula. The rule is overlapping with another rule. Excel only applies one conditional formatting rule to each cell.

How do you automatically color cells in Excel that contain a formula? ›

How to fill in colors in Excel cells based on value using a formula
  1. Determine which cells you want to format. ...
  2. Create your conditions for each cell. ...
  3. Open the "Conditional Formatting" menu. ...
  4. Select "New Rule" and a "Rule Type" option. ...
  5. Input the formula and formatting for that cell. ...
  6. Apply additional formulas to format the cells.
Apr 8, 2024

Can I have two conditional formatting rules in Excel? ›

When using conditional formats in Excel, you are not limited to only one rule per cell. You can apply as many rules as your business logic requires.

How to apply conditional formatting to entire column using formula? ›

Highlight an entire row or column
  1. Select the entire data range (excluding column headings).
  2. Open the New Formatting Rule dialog box by clicking the Conditional Formatting dropdown button and selecting New Rule.
  3. Select Use a formula to determine which cells to format.
  4. Enter the formula that describes your conditions.

What is the conditional formula for multiple conditions in Excel? ›

The Excel IF function with two or more conditions follows a generic formula: =IF(AND(condition1, condition2, ...), value_if_true, value_if_false). What this means is that “If condition 1 is true AND condition 2 is true, return value_if_true; else return value_if_false.”

How to apply conditional formatting to multiple cells using formula? ›

How to create a conditional formatting rule based on formula
  1. Select the cells you want to format. ...
  2. On the Home tab, in the Styles group, click Conditional formatting > New Rule…
  3. In the New Formatting Rule window, select Use a formula to determine which cells to format.
  4. Enter the formula in the corresponding box.
Aug 24, 2023

How to show cells with formulas in Excel? ›

Showing formulas in the cells makes it easy to find cells that contain formulas, or to check for errors. With a quick key combination you can see formulas instead of formula results in a worksheet. To show formulas in all cells press CTRL+` (that little mark is the grave accent mark key).

How to conditional format cells based on other cells? ›

On the Home tab of the ribbon. select Conditional Formatting > New Rule... Select 'Use a formula to determine which cells to format'. Enter a formula that evaluates to TRUE (or a non-zero number) if the rule should be applied, and to FALSE (or 0) otherwise.

Does conditional formatting work with formulas? ›

Conditional formatting quickly highlights important information in a spreadsheet. But sometimes the built-in formatting rules don't go quite far enough. Adding your own formula to a conditional formatting rule gives it a power boost to help you do things the built-in rules can't do.

How do I add two formulas in conditional formatting? ›

How to create multiple conditions in Excel
  1. Select the range to apply formatting rules.
  2. Click Home > Conditional Formatting > New Rule.
  3. Choose 'Use a formula to determine which cells to format', and type the formula: =AND(LEFT(F2,1)=” A”, RIGHT(F2,1)=” X”). ...
  4. Click on the Format button and add your preferred style.
Mar 2, 2023

Can conditional formatting be applied on cell values or formulas? ›

Select the cells that you want to conditionally format. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

Can I use an IF formula in conditional formatting in sheets? ›

Apply conditional formatting to an entire row

Highlight your entire data set (in this case, A3:F14 ), and select Format > Conditional formatting. Under Format cells if, select Custom formula is (last option).

How do you write an if then formula in Excel with multiple criteria? ›

The Excel IF function with two or more conditions follows a generic formula: =IF(AND(condition1, condition2, ...), value_if_true, value_if_false). What this means is that “If condition 1 is true AND condition 2 is true, return value_if_true; else return value_if_false.”

Top Articles
MEN'S 24/25 PRO HOME SHIRT LONG SLEEVE
Fire Resistant (FR) Shirts and Tops | Team Metron
Mchoul Funeral Home Of Fishkill Inc. Services
Aberration Surface Entrances
Diario Las Americas Rentas Hialeah
Uca Cheerleading Nationals 2023
I Make $36,000 a Year, How Much House Can I Afford | SoFi
What spices do Germans cook with?
Martha's Vineyard Ferry Schedules 2024
Jennette Mccurdy And Joe Tmz Photos
Teenbeautyfitness
Plus Portals Stscg
Paula Deen Italian Cream Cake
Pwc Transparency Report
Jscc Jweb
Shariraye Update
Mineral Wells Independent School District
Colorado mayor, police respond to Trump's claims that Venezuelan gang is 'taking over'
Price Of Gas At Sam's
Urban Dictionary: hungolomghononoloughongous
Gem City Surgeons Miami Valley South
Unterwegs im autonomen Freightliner Cascadia: Finger weg, jetzt fahre ich!
Pay Boot Barn Credit Card
91 East Freeway Accident Today 2022
Panic! At The Disco - Spotify Top Songs
Lola Bunny R34 Gif
Ou Class Nav
Jesus Revolution Showtimes Near Regal Stonecrest
8002905511
Ullu Coupon Code
Funky Town Gore Cartel Video
AP Microeconomics Score Calculator for 2023
Myfxbook Historical Data
How are you feeling? Vocabulary & expressions to answer this common question!
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
D-Day: Learn about the D-Day Invasion
Ashoke K Maitra. Adviser to CMD&#39;s. Received Lifetime Achievement Award in HRD on LinkedIn: #hr #hrd #coaching #mentoring #career #jobs #mba #mbafreshers #sales…
Hometown Pizza Sheridan Menu
South Bend Tribune Online
Stewartville Star Obituaries
Setx Sports
Exam With A Social Studies Section Crossword
How Big Is 776 000 Acres On A Map
Patricia And Aaron Toro
Babykeilani
St Vrain Schoology
Embry Riddle Prescott Academic Calendar
Wisconsin Volleyball titt*es
Premiumbukkake Tour
Turok: Dinosaur Hunter
Sitka Alaska Craigslist
Texas 4A Baseball
Latest Posts
Article information

Author: Edwin Metz

Last Updated:

Views: 5558

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edwin Metz

Birthday: 1997-04-16

Address: 51593 Leanne Light, Kuphalmouth, DE 50012-5183

Phone: +639107620957

Job: Corporate Banking Technician

Hobby: Reading, scrapbook, role-playing games, Fishing, Fishing, Scuba diving, Beekeeping

Introduction: My name is Edwin Metz, I am a fair, energetic, helpful, brave, outstanding, nice, helpful person who loves writing and wants to share my knowledge and understanding with you.