30 Advanced Excel Tips for 2026

Excel Champs / Excel Basics / Formulas in Conditional Formatting in Excel
By Puneet Gogia (Microsoft MVP)

Formulas in Conditional Formatting in Excel

30+ Advanced Excel Tips for 2026

No spam. Only Excel Stuff. God Promise. 😊

Select the range, then go to Home → Conditional Formatting → New Rule → Use a formula to determine which cells to format, enter a logical formula that returns TRUE or FALSE, set the format and click OK.

Write the formula relative to the active (top-left) cell of your selection. To highlight values under 1000 in E5:E20 with E5 active, use =E5<1000. Lock a column or row with $ when the rule should always read one place, for example =$E5<1000.

Combine tests with AND or OR. Between 15 and 35: =AND(E5>=15,E5<=35). Either of two conditions: =OR(E5<15,E5>35).

Common one-liners: shade alternate rows with =ISEVEN(ROW()), flag errors with =ISERROR(E5), and highlight duplicates with =COUNTIF($A$2:$A$100,A2)>1.

The usual trap is that a formula which works when typed in a cell misfires in a rule because the reference does not point at the active cell. Enter it with the correct cell active, and decide deliberately whether each reference should be relative or absolute.

The best part of conditional formatting is that you can use formulas in it. And the logic of working with formulas in it is very simple.

Your formula should be a logical formula and the result should be TRUE or FALSE. If the formula returns TRUE, you’ll get the formatting, and if FALSE, then nothing. The point is, by using formulas you can make the best out of conditional formatting.

Yes, that’s right. In the below example, we have used a formula in CF to check whether the value in the cell is smaller than 1000 or not.

use formulas in conditional formatting to check if value is greater

And if that value is smaller than 1000 it will apply the formatting which we have specified, otherwise not. So today in this post, I’d like to share with you simple steps to apply conditional formatting using a formula. And some of the useful examples that you can use in your daily work.

Steps to Apply Conditional Formatting with Formulas

The steps to apply CF with formulas are quite simple:

  1. Select the range to apply Conditional Formatting.
  2. Add a formula to test a condition.
  3. Specify a format to apply when the condition is met.
how to apply conditional formatting using a formula

To learn this in a proper way, make sure to download this sample file from here and follow the below-detailed steps.

  • First of all, select the range where you want to apply conditional formatting.
to apply conditional formatting using formulas select range
  • After that, go to Home Tab ➜ Styles ➜ Conditional Formatting ➜ New Rule ➜ Use a formula to determine which cells to format.
to apply conditional formatting using formulas click on new rule
  • Now, in the “Format values where formula is true” enter the below formula.

=E5<1000

to apply conditional formatting using formulas enter formula
  • The next thing is to specify the format to apply and for this, click on the format button and select the format.
to apply conditional formatting using formulas specify formatting
  • In the end, click OK.

While entering a formula in the CF dialog box, you can’t see its result or whether that formula is valid or not. So, the best practice is to check that formula before using it in CF by entering it in a cell.

How Cell References Work in a CF Formula

You write the formula for the first (top-left) cell of the selected range, and Excel adjusts it for every other cell, just like when you copy a formula. In the example above, the range starts at E5, so the formula uses E5, and for E6, Excel checks E6<1000, and so on.

  • Relative reference (E5): changes for each cell, so each cell checks its own value.
  • Column locked ($C2): every cell in a row checks column C of the same row, which is how you highlight an entire row.
  • Fully locked ($B$1): every cell checks the same cell, like a target or a checkbox cell.

For example, select A2:D20 and use the following formula to highlight every row where column C says “Done”:

=$C2="Done"

1. Use a Formula that is Based on Another Cell

You can apply conditional formatting based on another cell’s value. If you look at the below example, we have added a simple formula that is based on another cell. And if the value of that linked cell meets the condition specified, you’ll get conditional formatting.

apply conditional formatting with a formula using another cell

When the achievement is below 75%, it will be highlighted in red.

apply conditional formatting with a formula using another cell with percentage 75

2. Conditional Formatting using IF

Whenever I think about conditions, the first thing that comes to my mind is using the IF function. And the best part of this function is that it fits perfectly in conditional formatting. Let me show you an example:

using formulas to apply conditional formatting with if

Here, we have used the IF to create a condition and the condition is when the count of “Done” in range B3:B9 is equal to the count of tasks in the range A3:A9, then the final status will appear.

Just note that a CF rule doesn’t really need IF, because the condition itself returns TRUE or FALSE. So, the same rule can be written without IF, like the following formula, which is TRUE when every task in A3:A9 is marked “Done” in B3:B9:

=COUNTIF($B$3:$B$9,"Done")=COUNTA($A$3:$A$9)
this formula in conditional formatting will format cell when all the tasks are done

3. Conditional Formatting with Multiple Conditions

You can create multiple checks in a condition to apply the format. Once all the conditions (or one of the conditions) are met, conditional formatting will apply to the cell. Look at the below example where we have used the average temperature of my town.

And we have used a simple IF-AND combination to highlight the months when the temperature is pretty pleasant. Months where the temperature is between 15 and 35 degrees Celsius will get colored.

use if and formula in conditional formatting to highlight cell with temperatures

Just like this, you can also use IF with the OR function.

With AND alone, the rule for a temperature in cell B2 looks like the following formula (use OR instead when any one condition is enough):

=AND(B2>=15,B2<=35)

4. Highlight Alternate Rows with Conditional Formatting

To highlight every alternate row, you can use the following formula in CF.

=INT(MOD(ROW(),2))

By using this formula, every row whose number is odd will be highlighted. And if you want to do the opposite, you can use the following formula.

table with highlighted alternate rows using formula in conditional formatting

=INT(MOD(ROW()+1,2))

The same kind of formula can be used for columns (odd and even) as well.

=INT(MOD(COLUMN(),2))

And for even columns.

=INT(MOD(COLUMN()+1,2))

You can also use ISODD and ISEVEN, which are easier to read. The following formula highlights the even rows:

=ISEVEN(ROW())
use conditional formatting highlight column alternate

5. Highlight Cells with Errors using CF

Now let’s come to another example where we will check whether a cell contains an error or not. What we need to do is just insert a formula in conditional formatting that can check the condition and return the result in TRUE or FALSE. You can even verify cells for numbers, text, or some specific values as well.

For a range that starts at A1, the formula is the following. Use ISNUMBER or ISTEXT in the same way to check for numbers or text:

=ISERROR(A1)
highlight errors from cells using conditional formatting

6. Create a Checklist with Conditional Formatting

Now let’s add some creativity to intelligence. You have already learned how to use a formula that is based on another cell. Here we have linked a checkbox with the B1 cell and further linked the B1 with the formula used in conditional formatting for cell A1.

checklist using conditional formatting and checkbox

Now, if you tick mark the checkbox, the value of cell B1 will turn into TRUE, and cell A1 gets its conditional formatting [strikethrough].

a dynamic checklist using formulas in conditional formatting

The formula in the rule for A1 is simply the following:

=$B$1=TRUE

7. Highlight Duplicates and Past Dates

Two more formulas that come in handy. To highlight the values that appear more than once in A2:A20, select the range and use:

=COUNTIF($A$2:$A$20,A2)>1

And to highlight the dates before today in a range that starts at B2 (blank cells are left out):

=AND(B2<>"",B2<TODAY())

Points to Remember

  1. Your formula should be a logical formula, which leads to a result as TRUE or FALSE.
  2. Try not to overload your data with conditional formatting.
  3. Always use relative and absolute references in a proper sense.

To edit or delete a rule later, go to Home ➜ Conditional Formatting ➜ Manage Rules, and choose “This Worksheet” in the “Show formatting rules for” drop-down to see all the rules on the sheet.

Sample File

Download this sample file from here to learn more.

Frequently Asked Questions

Why does my conditional formatting formula not work?

Most often, the references don’t match the selection. Write the formula for the top-left cell of the selected range, and check which parts need a $. When you click a cell to enter it, Excel adds $ to both the column and the row, so remove the ones you don’t need.

Can I refer to another sheet in a CF formula?

Yes, in Excel 2010 and later, you can refer to cells on another sheet of the same workbook, like =A2>Sheet2!$B$1. References to other workbooks are not allowed.

Does a CF formula need to return TRUE or FALSE?

It should. Excel also treats any number other than 0 as TRUE and 0 as FALSE, which is why the MOD formulas above work. A formula that returns text or an error doesn’t apply the format.

Puneet Gogia

Written by

Puneet Gogia

Microsoft MVP — Excel · Founder, Excel Champs

Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.

3M+ readers helped
1,000+ tutorials written
Since 2015 teaching Excel

7 thoughts on “Formulas in Conditional Formatting in Excel”

  1. 1) Sir, your tutorial has helped me in many different ways. But I want to know one thing that when we are writing the formulas in the cell then those formulas are visible or going in the formula bar. I want to write that formula or formulas by VBA to solve the problem. How is it possible? If you give a detailed guide, it will be very helpful. For example, I am doing Date of Retirement calculation with EOMONTH or I am writing a specific formula in a cell to calculate Present Age. I want to run these formulas with VBA. How to do? That means, I will write date of birth in one cell and present age in another cell and Retirement Date will be written in another cell simultaneously/automatically.
    2) In those cells that cannot be duplicate entries, how can it be solved by conditional formatting? Means, I wrote the ID code in a cell, in the next case when entering that ID, a massage will show that this ID has been entered. It would be very helpful to know in detail how it can be solved.

    Reply
  2. how to change cell value ( many cells ) to comments at once??

    Reply
  3. hi, I need an example for my excel class to teach on conditional formatting and spark lines.

    Reply
  4. I have scenario
    I need to use Cond formatting with formula like
    If I want to show some text in the formatted cell .
    Example
    cell A1 value starting with “2” like 2806 text need to show : “RJB” in Cell B1.
    if Cell A1 Value starting with “4” like 4739 text need to show : “HBB” in cell B1
    anyone have solution please send me a email on
    [email protected]
    Thanks.

    Reply

Leave a Comment