The Excel Conditional Formatting Method Nobody Talks About

Sep 10, 2026 • 6 min read

Most Excel conditional formatting rules look at the value inside a cell. If a number is negative, make it red. If it exceeds a target, give it a green fill.

But financial reports often need something different. A row needs formatting because it is a total or subtotal, not because of the number it contains. And when the report layout changes, that formatting needs to move with it.

The solution is to look up the required style from a layout table inside a conditional formatting formula. It is a powerful technique for dynamic Profit & Loss reports, Balance Sheets, and other structured financial reports.

What You'll Learn

  • Use a layout table to assign formatting based on each row’s role in the selected report.
  • Test FILTER formulas in worksheet cells before moving them into conditional formatting rules.
  • Replace structured references with standard cell references when creating the conditional formatting formulas.
  • Apply rules to a range large enough to accommodate the longest dynamic report layout.

Table of Contents

Format the Report Hierarchy, Not the Cell Value

Consider a P&L with two layouts: a detailed view and a summary view.

In the detailed P&L, gross profit, overheads, and profit before tax are subtotals. EBIT and profit after tax are totals. Those rows need different formatting so the structure is easy to follow.

When we switch to the summary P&L, the report becomes shorter. Gross profit still needs subtotal formatting, while EBIT and profit after tax still need total formatting. But overheads is now a single summary line rather than a subtotal beneath a list of expenses, so it no longer needs subtotal formatting.

A rule based only on the heading “Overheads” would miss that distinction. A rule tied to a fixed row number would also fail when the report changes length.

Instead, we need to answer two questions:

  • Which report layout is selected?
  • What style should this heading use in that layout?

That combination lets the formatting follow the row’s role in the report hierarchy.

Set Up a Table That Defines the Layout and Style

The example workbook contains two worksheets:

  • Data: General ledger information and a mapping table connecting ledger codes to P&L headings.
  • Report: The finished report area and a table defining the available report layouts.

The layout table contains three important columns:

  • Name: The report layout, such as Detailed P&L or Summary P&L.
  • Heading: The label to display in the report.
  • Style: The formatting category, such as Total, Subtotal, or a blank cell for no special formatting.
Excel worksheet with a P&L report on the left and a layout table containing Name, Heading, and Style columns
The layout table defines both the report headings and the style each heading needs.

A data validation list in cell C3 switches between the two layouts. Formulas then generate the report headings and values for the selected layout.

Those report-building formulas are separate from the formatting technique. Here, we are focusing on how to make the appearance respond to the selected layout.

If you want to work with the same workbook, it is available through the free Insiders Programme. Look for file reference 0334 CF Hierarchy Formatting.

Build and Test the Formatting Formula in a Cell

Before putting a formula into conditional formatting, I like to test it in ordinary worksheet cells. It is much easier to see whether the logic is working.

A formula-based conditional formatting rule applies its format when the result is TRUE, or a nonzero number that Excel treats as TRUE. It does not apply the format when the result is FALSE or zero.

So, our task is to turn the style stored in the layout table into a TRUE or FALSE result for each report row.

1. Look up the style using two conditions

Start in cell E7, alongside the first report heading in B7. Using the table name Layout, the lookup formula is:

=FILTER(Layout[Style],(Layout[Name]=$C$3)*(Layout[Heading]=$B7))

This uses the FILTER function to return the style where both conditions are met:

  • Layout[Name]=$C$3 matches the selected report layout.
  • Layout[Heading]=$B7 matches the heading on the current report row.

Multiplying the two conditions means both must be TRUE for the row to be included.

For Income, the matching style cell is blank, so the lookup returns zero. For rows requiring special formatting, it returns the text Total or Subtotal.

2. Lock the references correctly

The references need to behave correctly when the formula is copied down and, later, evaluated across the report:

  • $C$3: Lock both the column and row. Every calculation must use the same layout selector.
  • $B7: Lock the heading column, but leave the row relative. Each report row must check its own heading.

Use F4 while editing a reference to cycle through the locking options.

Copy the formula down beside the report. You should now see the style required for each heading in the selected layout.

3. Convert the lookup into a TRUE or FALSE test

The style text tells us what to do, but the conditional formatting rule needs a logical result. For the total rows, compare the lookup result with "Total":

=FILTER(Layout[Style],(Layout[Name]=$C$3)*(Layout[Heading]=$B7))="Total"

Copy this formula down. In the summary P&L, EBIT and profit after tax should return TRUE. The other report rows should return FALSE.

Next, copy the formula across to a second test column and change the comparison to "Subtotal":

=FILTER(Layout[Style],(Layout[Name]=$C$3)*(Layout[Heading]=$B7))="Subtotal"

Copy that down too. Now you can check the total and subtotal rules side by side.

P&L worksheet with Total and Subtotal test columns displaying TRUE and FALSE results
Testing the formulas in worksheet cells makes it easy to check which rows will receive each format.

Once those results are correct, we have the logic we need. The next step is to move it into conditional formatting.

Apply the Total Formatting Rule

There is one important consideration with dynamic array reports: the conditional formatting range does not automatically expand and contract with the spilled values.

For this approach, select a report area large enough to contain the longest layout you expect to use. In the example, the selection extends down to row 30.

  1. Copy the total formula from the formula bar, without changing its references.
  2. Select the report heading and value cells to format, starting on row 7 and extending down to row 30.
  3. Go to Home > Conditional Formatting > New Rule.
  4. Select Use a formula to determine which cells to format.
  5. Paste the total formula into the formula box.

Replace the structured references

The worksheet formula uses table structured references, such as Layout[Style]. These cannot be used directly in the conditional formatting formula box in this method, so replace them with standard cell references.

Within the formula box, replace each table reference by selecting its corresponding data cells:

  • Replace Layout[Style] with the cells in the Style column.
  • Replace Layout[Name] with the cells in the Name column.
  • Replace Layout[Heading] with the cells in the Heading column.

Use absolute references for these lookup ranges, and select matching rows in all three columns. Keep $C$3 and $B7 as they are.

New Formatting Rule dialog with a FILTER formula using standard cell references and a Total comparison

Click Format and set the total style to:

  • Bold font.
  • White font color.
  • Black fill.

Click OK, then OK again to create the rule. The total rows should now have the required formatting across the selected report columns.

Duplicate the Rule for Subtotals

We do not need to build the second rule from scratch. It uses the same lookup, with a different style comparison.

  1. Go to Home > Conditional Formatting > Manage Rules.
  2. Select the total rule and choose Duplicate Rule.
  3. Edit the duplicated rule.
  4. Change "Total" to "Subtotal" in the formula.
  5. Click Format and choose a light gray fill with bold, black text.
  6. Confirm the changes and click Apply.

We now have two rules using the same layout table: one for totals and one for subtotals.

Switch Layouts and Check the Result

Use the data validation list to switch between Detailed P&L and Summary P&L.

The headings and values update, and the formatting follows them. Gross profit retains its subtotal style, while EBIT and profit after tax retain their total style. Overheads receives subtotal formatting in the detailed report, but not in the summary report.

Summary P&L with a gray gross profit row and black EBIT and profit after tax rows beside the layout table
The summary layout keeps the appropriate total and subtotal styles without formatting Overheads as a subtotal.

That is the key to this method. The conditional formatting rule looks up the row’s role in the selected layout, rather than relying on a fixed position or the amount in the cell.

The layout table holds the formatting decisions. The formulas turn those decisions into TRUE or FALSE results. Conditional formatting applies the appearance. Together, they let the report change layout without losing its visual hierarchy.

Build the Dynamic Report Behind the Formatting

If you want to understand how to generate the changing headings and values, my free Modern Excel Reporting with FILTER course covers that part of the process. It focuses on building the dynamic report itself, rather than just applying the formatting.

Share

Excel Off The Grid

I help you reduce repetitive Excel work with practical guides to formulas, Power Query, reporting, and automation.

© 2026 Excel Off The Grid
Powered by Convella