Applying Formula-Based Conditional Formatting in Microsoft Excel
Course: Advanced Excel
Topic: Applying Formula-Based Conditional Formatting
Course Link: Advanced Excel Course – JustAcademy
Demo Link: Register for a Free Course Demo
Website: Visit JustAcademy
1. Introduction to Formula-Based Conditional Formatting
Formula-based conditional formatting is an advanced Microsoft Excel feature that automatically changes the appearance of cells when a specified formula evaluates to TRUE. It allows users to create customized formatting rules that go beyond standard options such as highlighting duplicate values, cells greater than a particular number, or dates within a specific period.
Using formulas, you can highlight entire rows, identify overdue tasks, compare values across columns, detect duplicate records, flag low-stock products, identify employees who meet performance targets, and create dynamic reports. The formatting updates automatically when the underlying data changes.
For example, a sales manager can highlight an entire sales record in green when the sales amount exceeds the target and in red when the target is missed.
2. Learning Objectives
- Understand formula-based conditional formatting and its purpose.
- Create custom rules using logical formulas.
- Apply relative, absolute, and mixed cell references correctly.
- Use functions such as AND, OR, NOT, COUNTIF, TODAY, MOD, and ROW.
- Highlight entire rows based on a condition in one or more columns.
- Identify overdue tasks, duplicate entries, and performance exceptions.
- Manage, edit, copy, and troubleshoot conditional formatting rules.
3. What Is Conditional Formatting?
Conditional formatting is an Excel feature that applies visual formatting to cells when specified conditions are satisfied. Formatting can include background colors, font colors, bold text, borders, and other supported cell-format options.
Formula-based conditional formatting uses a logical formula to determine whether a selected cell or row should receive a particular format.
| Feature |
Description |
Example |
| Standard conditional formatting |
Uses built-in conditions. |
Highlight values greater than 500. |
| Formula-based conditional formatting |
Uses a custom logical formula. |
Highlight a row when sales exceed the target. |
| Dynamic formatting |
Reevaluates rules as data changes. |
Highlight tasks that become overdue. |
| Multi-condition formatting |
Combines multiple tests in one formula. |
Highlight sales above target in a specific region. |
4. How Formula-Based Conditional Formatting Works
Excel evaluates the formula for each relevant cell in the selected range. If the formula returns TRUE, Excel applies the chosen formatting. If the formula returns FALSE, the rule does not apply its formatting.
For example, the formula below checks whether a value in cell B2 is greater than 100.
=B2>100
If B2 contains 150, the formula returns TRUE. If B2 contains 80, it returns FALSE.
In a conditional formatting rule, the formula should begin with an equals sign (=) and should normally return a logical result, TRUE or FALSE.
5. Steps to Create a Formula-Based Rule
- Open your Excel workbook and select the cells or range you want to format.
- Go to the Home tab.
- Select Conditional Formatting.
- Click New Rule.
- Select Use a formula to determine which cells to format.
- Enter your logical formula in the formula box.
- Click Format and choose a fill color, font style, font color, or border.
- Click OK to save the rule and apply it to the selected range.
- Change the source data to confirm that the formatting responds correctly.
Important: The formula's cell references must be designed for the top-left cell of the selected range. Excel adjusts relative references as it evaluates the rule across the range.
6. Understanding Cell References in Conditional Formatting
Cell references determine which values Excel checks as it evaluates a conditional formatting rule. Incorrect references are one of the most common reasons for unexpected formatting.
| Reference Type |
Example |
Behavior |
Typical Use |
| Relative |
A2 |
Both the column and row can change when the formula is evaluated elsewhere. |
Check each row's value. |
| Absolute |
$A$2 |
Both the column and row remain fixed. |
Compare against one fixed cell. |
| Mixed column |
$A2 |
Column A remains fixed while the row can change. |
Check a particular column for every row. |
| Mixed row |
A$2 |
Row 2 remains fixed while the column can change. |
Compare values against a fixed header row. |
Suppose you select the range A2:D10 and enter =$C2>500. Excel checks column C for each row while allowing the row number to change. If the condition is TRUE, the formatting can be applied across all four columns of that row.
7. Example 1: Highlight Sales Above a Target
Assume a worksheet contains the following sales data:
| Employee |
Sales |
Target |
Status |
| Amit |
65000 |
50000 |
Above Target |
| Neha |
42000 |
50000 |
Below Target |
| Rahul |
72000 |
60000 |
Above Target |
To highlight sales values that exceed their corresponding targets:
- Select the sales range B2:B4.
- Choose Home > Conditional Formatting > New Rule.
- Select the formula-based rule option.
- Enter the formula below.
=B2>C2
Choose a green fill and confirm the rule. The sales values for Amit and Rahul will be highlighted because they exceed their targets.
Why it works: Both references are relative, so Excel compares B2 with C2, B3 with C3, and B4 with C4 as it evaluates the rule.
8. Example 2: Highlight an Entire Row Based on a Condition
Sometimes highlighting only one cell is insufficient. In reports, you may want the entire record to stand out when a specific condition is met.
Consider a sales report with these columns:
- Column A: Employee Name
- Column B: Department
- Column C: Sales Amount
- Column D: Target Amount
To highlight entire rows where sales exceed the target:
- Select the full data range A2:D100.
- Create a new formula-based conditional formatting rule.
- Enter the following formula.
=$C2>$D2
- Choose a suitable fill color and click OK.
Explanation: The dollar signs lock columns C and D, while the row number changes for each record. Excel evaluates the sales and target for each row and formats all cells in that row when the condition is TRUE.
9. Example 3: Combine Multiple Conditions Using AND
The AND function returns TRUE only when every specified condition is TRUE. It is useful when a record must meet several requirements simultaneously.
Suppose a company wants to highlight employees who belong to the Sales department and have sales greater than 50,000.
=AND($B2="Sales",$C2>50000)
Apply the rule to the full employee data range, such as A2:D100.
This formula checks two conditions:
- The department in column B must be Sales.
- The sales value in column C must exceed 50,000.
Only rows that satisfy both conditions will receive the chosen formatting.
10. Example 4: Use OR to Match Any Condition
The OR function returns TRUE if at least one specified condition is TRUE. It is useful for identifying records that meet any one of several criteria.
For example, highlight employees whose sales are below 30,000 or whose department is Support.
=OR($C2<30000,$B2="Support")
Apply this rule to the full data range. A row will be highlighted when either condition is satisfied, including when both conditions are satisfied.
11. Example 5: Highlight Duplicate Records Using COUNTIF
The COUNTIF function counts the number of cells in a range that meet a specified criterion. In conditional formatting, it can identify repeated values or duplicate records.
Suppose employee IDs are stored in A2:A100. To highlight IDs that appear more than once, select A2:A100 and use:
=COUNTIF($A$2:$A$100,A2)>1
Excel counts how often each ID appears in the specified range. If the count exceeds one, the cell is highlighted.
To highlight the entire row when an employee ID is duplicated, select A2:D100 and use the same formula:
=COUNTIF($A$2:$A$100,$A2)>1
The absolute range stays fixed, while the employee ID reference adjusts to each row.
Note: This method highlights every occurrence of a duplicated ID, including the first occurrence.
12. Example 6: Highlight Overdue Tasks Using TODAY
The TODAY function returns the current date. Combined with a status check, it can automatically identify tasks whose due dates have passed and that are not yet complete.
Assume the worksheet contains:
- Column A: Task Name
- Column B: Due Date
- Column C: Status
Select the task range A2:C100 and create a formula-based rule using:
=AND($B2<TODAY(),$C2<>"Completed",$B2<>"")
This rule highlights tasks with a past due date, excludes tasks marked Completed, and avoids highlighting rows with a blank due date.
Because TODAY updates with the current date when Excel recalculates, the rule can automatically flag additional overdue tasks over time.
13. Example 7: Highlight Blank Cells in a Required Field
Blank-cell detection is useful for quality checks in forms, customer lists, employee records, and reporting datasets.
To highlight missing email addresses in column D, select D2:D100 and use:
=D2=""
This formula returns TRUE when the referenced cell is empty or evaluates to an empty text string. If you want to identify cells containing only spaces, use a formula such as:
=LEN(TRIM(D2))=0
The second formula also detects values made up entirely of ordinary spaces. Choose a warning color to make missing information easy to identify.
14. Example 8: Alternate Row Shading Using MOD and ROW
Alternating row colors can improve readability in large datasets. You can create this effect with formula-based conditional formatting instead of manually coloring rows.
- Select the required data range, for example A2:F100.
- Create a new formula-based rule.
- Enter the formula below.
=MOD(ROW(),2)=0
The ROW function returns the row number, while MOD returns the remainder after division. When the remainder is zero, Excel applies the selected format to even-numbered worksheet rows.
To shade odd-numbered worksheet rows instead, use:
=MOD(ROW(),2)=1
If you want alternating rows based on the first row of your selected range rather than the worksheet's row numbers, use a formula such as:
=MOD(ROW()-ROW($A$2),2)=0
15. Example 9: Highlight Values Above the Average
The AVERAGE function calculates the arithmetic mean of a numeric range. It can be used in a conditional formatting formula to identify values above or below the overall average.
Suppose sales figures are stored in C2:C100. Select the same range and use:
=C2>AVERAGE($C$2:$C$100)
Excel highlights sales values greater than the average of the specified dataset. The average range is fixed so that it remains consistent while the current-row reference changes.
This approach is useful for comparing employee performance, product revenue, student marks, and monthly results.
16. Example 10: Highlight Values Within a Specific Range
Use AND when a value must fall between two boundaries.
For example, highlight sales values between 20,000 and 50,000:
=AND(C2>=20000,C2<=50000)
Apply the rule to the required sales range. Values equal to either boundary are included because the formula uses greater-than-or-equal-to and less-than-or-equal-to operators.
For a condition that excludes the boundary values, use:
=AND(C2>20000,C2<50000)
17. Example 11: Highlight Dates in the Next 7 Days
Formula-based conditional formatting can also support deadline tracking. Suppose due dates are in column B and you want to highlight dates from today through the next seven days.
Select B2:B100 and use:
=AND(B2>=TODAY(),B2<=TODAY()+7)
This rule highlights dates that are today or within the following seven days. Blank cells are normally not treated as future dates by this formula, but if your dataset contains unusual values, add a blank check:
=AND(B2<>"",B2>=TODAY(),B2<=TODAY()+7)
For a task tracker, you can apply the rule to the entire row by using a locked date column:
=AND($B2<>"",$B2>=TODAY(),$B2<=TODAY()+7)
18. Example 12: Highlight Negative Profit
Profit and loss reports often need to identify negative values quickly. If profit is recorded in column E, select E2:E100 and enter:
=E2<0
Choose a red fill or another clearly visible warning format. To highlight the entire row when profit is negative, select A2:F100 and use:
=$E2<0
This makes loss-making transactions easier to locate during financial analysis.
19. Common Formula Functions Used in Conditional Formatting
| Function |
Purpose |
Example |
| AND |
Checks whether all conditions are TRUE. |
=AND(B2>100,C2="Yes") |
| OR |
Checks whether at least one condition is TRUE. |
=OR(B2<50,C2="Pending") |
| NOT |
Reverses a logical result. |
=NOT(B2="Approved") |
| COUNTIF |
Counts matching cells. |
=COUNTIF($A$2:$A$100,A2)>1 |
| SUMIF |
Calculates a conditional total. |
=SUMIF($A$2:$A$100,A2,$B$2:$B$100)>1000 |
| TODAY |
Returns the current date. |
=B2<TODAY() |
| ROW |
Returns a row number. |
=MOD(ROW(),2)=0 |
| MOD |
Returns the remainder of a division. |
=MOD(ROW(),2)=1 |
| ISBLANK |
Tests whether a cell is blank. |
=ISBLANK(D2) |
| LEN and TRIM |
Can identify text containing only spaces. |
=LEN(TRIM(D2))=0 |
| IFERROR |
Handles errors in a calculation. |
=IFERROR(A2/B2,0)>10 |
Important: The formula entered in a conditional formatting rule should evaluate to TRUE or FALSE. Functions such as SUMIF can be used within a larger comparison that returns a logical result.
20. Managing and Editing Conditional Formatting Rules
After creating multiple rules, you may need to update their formulas, change their formats, or adjust the ranges to which they apply.
20.1 Open the Rules Manager
- Select a cell within the formatted range.
- Go to Home > Conditional Formatting > Manage Rules.
- Choose whether to view rules for the current selection or the entire worksheet, where supported by your Excel version.
- Select a rule and click Edit Rule to change its formula or formatting.
20.2 Change the Applied Range
Review the Applies to range to ensure that the rule covers the intended cells. For example, a rule intended for A2:D100 should not accidentally apply only to A2:A100.
20.3 Change Rule Priority
When multiple rules apply to the same cells, rule order and settings such as Stop If True can affect the final result. Use the Rules Manager to review the order and adjust priorities where necessary.
20.4 Delete or Clear Rules
Use Home > Conditional Formatting > Clear Rules to remove conditional formatting from selected cells or an entire worksheet. You can also delete individual rules in the Rules Manager.
21. Copying Formula-Based Conditional Formatting
You can reuse conditional formatting by copying a formatted cell or range with Format Painter. However, copying a formula-based rule can change relative references based on the destination range.
- Select a cell or range that already has the required conditional formatting.
- Go to Home > Format Painter.
- Select the destination cells or range.
- Open Manage Rules and verify the formula and Applies to range.
For example, a formula using =C2>D2 may adjust its references when copied. If the formula must always check column C against column D, consider locking the columns with =$C2>$D2.
22. Common Mistakes and Troubleshooting
| Problem |
Possible Cause |
Solution |
| No formatting appears. |
The formula is invalid or evaluates to FALSE. |
Test the formula in a worksheet cell and verify its logic. |
| The wrong row is highlighted. |
The formula uses incorrect row references. |
Write the formula for the top-left cell of the applied range. |
| Every row gets the same format. |
A reference may be locked incorrectly. |
Review the use of dollar signs in the formula. |
| Only one cell changes color. |
The Applies to range is too small. |
Expand the range to include all intended cells. |
| Whole-row formatting is incorrect. |
The relevant columns are not locked. |
Use mixed references such as =$C2>$D2. |
| Duplicate detection is inaccurate. |
The formula references the wrong range or identifier column. |
Check the COUNTIF range and current-cell reference. |
| Date rules behave unexpectedly. |
Dates may be stored as text or blank cells may be included. |
Convert dates to valid Excel dates and add blank checks. |
| A different color appears than expected. |
Another rule overlaps the same cells. |
Review rule order, overlapping ranges, and Stop If True. |
| Some cells do not format. |
The formula contains errors or data types are inconsistent. |
Check source values and use error handling where appropriate. |
23. Best Practices for Formula-Based Conditional Formatting
- Keep formulas simple and readable wherever possible.
- Use the correct relative, absolute, and mixed references for the applied range.
- Test formulas with both matching and nonmatching examples before applying them to large datasets.
- Use clear and consistent colors to distinguish warnings, success conditions, and neutral states.
- Include blank-cell checks when missing data should not be highlighted.
- Ensure that date values are stored as valid Excel dates rather than inconsistent text strings.
- Check the Applies to range after copying or modifying rules.
- Avoid creating numerous overlapping rules without a clear priority strategy.
- Use Excel Tables where appropriate so that structured datasets can expand more conveniently.
- For large workbooks, avoid unnecessarily complex formulas and excessively broad applied ranges.
- Document important business rules so other users understand why a cell is highlighted.
24. Practical Exercise: Create a Sales Performance Dashboard
Objective: Build a worksheet that automatically highlights performance exceptions and helps managers identify important records.
Sample Dataset
| Employee |
Department |
Sales |
Target |
Due Date |
Status |
| Amit |
Sales |
65000 |
50000 |
2026-10-25 |
Completed |
| Neha |
Sales |
42000 |
50000 |
2026-10-26 |
Pending |
| Rahul |
Support |
25000 |
30000 |
2026-10-24 |
Pending |
| Priya |
Sales |
72000 |
60000 |
2026-10-29 |
Completed |
Tasks
- Highlight entire rows where sales exceed the target.
- Highlight sales values below the target in red.
- Highlight pending tasks whose due dates have passed.
- Highlight records belonging to the Support department.
- Add alternating row shading for improved readability.
Suggested Formulas
| Requirement |
Formula |
Apply To |
| Sales exceed target |
=$C2>$D2 |
A2:F100 |
| Sales below target |
=C2<D2 |
C2:C100 |
| Overdue pending tasks |
=AND($E2<TODAY(),$F2="Pending",$E2<>"") |
A2:F100 |
| Support department |
=$B2="Support" |
A2:F100 |
| Alternate rows |
=MOD(ROW()-ROW($A$2),2)=0 |
A2:F100 |
Expected result: The worksheet should update its formatting as sales figures, targets, due dates, and statuses change. Review overlapping rules carefully so that one format does not hide another important warning.
25. Interview Questions and Answers
Q1. What is formula-based conditional formatting?
Answer: It is an Excel feature that applies formatting when a custom logical formula evaluates to TRUE.
Q2. What must a conditional formatting formula return?
Answer: A logical result, TRUE or FALSE. Excel applies the rule's formatting when the condition is TRUE.
Q3. Why are dollar signs used in conditional formatting formulas?
Answer: Dollar signs lock a row, column, or both so that references behave correctly when Excel evaluates the formula across a range.
Q4. How do you highlight an entire row based on one column?
Answer: Select the full data range and use a formula with a locked column and a relative row reference. For example, =$C2>50000 highlights rows where column C exceeds 50,000.
Q5. How can duplicate values be identified using a formula?
Answer: Use COUNTIF, for example =COUNTIF($A$2:$A$100,A2)>1, to identify values that appear more than once.
Q6. How can you highlight overdue dates dynamically?
Answer: Use TODAY in a formula, such as =B2<TODAY(). Add status and blank checks if the business requirement needs them.
Q7. What is the difference between AND and OR?
Answer: AND returns TRUE when all conditions are TRUE. OR returns TRUE when at least one condition is TRUE.
Q8. Why might a conditional formatting rule highlight the wrong cells?
Answer: Common reasons include incorrect relative references, incorrect absolute references, an incorrect Applies to range, or conflicting rules.
Q9. Can conditional formatting rules be copied?
Answer: Yes. Format Painter can copy formatting rules, but formulas and applied ranges should be checked after copying.
Q10. What is the advantage of formula-based formatting over standard rules?
Answer: It supports customized business logic, multiple conditions, comparisons across columns, whole-row highlighting, and dynamic checks that built-in rules may not directly provide.
26. Quick Revision Checklist
- Formula-based conditional formatting uses a logical formula to evaluate a condition.
- TRUE applies the selected formatting; FALSE does not.
- Use Home > Conditional Formatting > New Rule to create a custom formula rule.
- Relative references change as the formula is evaluated across cells.
- Absolute references remain fixed, while mixed references lock only a row or column.
- AND, OR, COUNTIF, TODAY, MOD, and ROW are useful for common advanced rules.
- Lock columns when highlighting entire rows based on a specific field.
- Review the Applies to range and rule priority when formatting behaves unexpectedly.
- Test formulas with sample data before applying rules to large datasets.
27. Conclusion
Formula-based conditional formatting is an essential advanced Excel skill for creating interactive reports, identifying exceptions, and improving data quality. By combining logical tests with functions such as AND, OR, COUNTIF, TODAY, MOD, and ROW, users can create flexible rules for sales analysis, deadline monitoring, duplicate detection, financial reporting, and performance tracking.
Understanding cell references and rule management is key to applying formatting accurately. Practice these techniques with real datasets to build clear, reliable, and dynamic Excel dashboards.
Explore Advanced Excel Training
Learn more about advanced Excel formulas, reporting, data cleaning, and analysis through JustAcademy.
Explore the Advanced Excel Course
Register for a Course Demo
Visit the JustAcademy Website