Ravindra BagaleCourses & study guides मराठी Track your progress

2. Data Entry Tools

Excel

2.8 Formula-based Conditional Formatting

1. Use a formula when a row's appearance depends on more than one fact

A student production team manages invoices for a screened short film. Stakeholders might be familiar with planning tools for sharing a video on Instagram or viewing subscription expenses from Netflix. The group still keeps its own small request worksheet. It wants to review requests that are still pending and have a deadline before the review date. A costly request needs a separate approval. A cancelled request should look clearly inactive. Those three requirements use different parts of each request row.

Use a formula-based conditional format to turn each requirement into a true or false decision. The rule is an expression that Excel evaluates for the cells in its Applies To range. A true result permits the assigned format. Keep the rule's inputs and the displayed values inspectable. The display alone cannot tell you how many stored records met the condition, whether a reviewer resolved the issue or who owns the next action. This page uses invented dates and amounts and no application or client data.

Build the condition as an ordinary formula first. Verify which rows return TRUE. Move it into Conditional Formatting once the conditions are correct. Inspect the selected range and reference movement before reading the visual result.

A rule for A2 through E4 reads status in fixed column D. Row 2 reads D2, row 3 reads D3, and row 4 reads D4 because the row reference is relative.
Use the same status column for each cell of a row. Let the checked row number move down.

Begin with a stable row and a real question

For this lesson, A contains the request ID, B contains its owner, C contains the due date, D contains status and E contains quoted INR. You might want to shade the whole row when status is Cancelled. If you apply a formula rule to $A$2:$E$9 with =$D2="Cancelled", all five target cells on row 2 refer to D2. On row 3, all five check D3. This is what connects the colour across the row to one stored status field.

Choose an explicit true and false case. D2 might say Complete and D3 might say Cancelled. Point the condition at each resulting row in ordinary helper cells. Expect FALSE for Complete and TRUE for Cancelled. The rule does not need to change D itself. A colour around the whole record helps someone read the related identifier, owner and amount without losing their place.

Move one fact at a time

Where each formula reference would point from a range starting at A2
ReferenceMove right one destination cellMove down one destination row
D2E2D3
$D2D2D3
D$2E2D2
$D$2D2D2

Start from the first target cell or selection origin, and verify the active cell when creating or editing a rule. In the main lab start at A2 and select across and down to E9. The row number in $D2 matches the first selected row. If you change the Applies To start to row 3 but leave the rule thinking it starts at row 2, a report can appear offset by one record. Inspect the actual saved formula and compare two neighbouring rows with different statuses.

Ordinary worksheet references can change as formulas are copied. Excel uses the same relative and absolute concepts when applying a formula rule across a range. Selecting a different cell in a formula editor may insert absolute references by default. Inspect both dollar signs instead of assuming Excel knows which part you want to move. The intended shared cutoff may need both dollar signs, while the current row field needs exactly one on its column.

2. Decide which conditions must hold together

Read an AND rule as a sentence

For an overdue flag, write the actual rule in words. A row has a request ID, its status is Pending, its due date and the report date are numeric date values, and its deadline is earlier than the report date. AND means all these tests must be true. If you instead use OR, a Pending request might be marked even if its due date is next week. OR is useful for alternate routes to a decision, such as a record that is either Cancelled or Refunded. Speak the condition aloud before writing it.

Do not compare the wrong units. The due date is a worksheet date serial. The report date is stored in H2 as another serial. A formula such as $C2<$H$2 checks which numeric date is earlier. Comparing to displayed date text may give a different result. Label H2 Review date and use an explicit DATE input in the lab. Hold the date still so every learner sees the same output. For a live queue use TODAY only when the policy truly needs the current calendar day and the viewers understand when recalculation takes place.

Use a guard for incomplete rows. A row with no request ID should not be marked overdue simply because a previous template date remains. A blank date can behave like zero in some numeric comparisons, which may look like an extremely old due date. Use ISNUMBER to distinguish a usable number from a text value or blank. ISNUMBER alone does not prove that a number was the intended calendar date. Verify the typed source and its meaning too.

Make errors visible in the audit, even if the format stays quiet

Excel's rule formatting may not apply when an expression returns an error. Wrap a rule with IFERROR where appropriate so a calculation error does not produce a misleading style. Then use a plain audit column to flag the underlying problem explicitly. A false result from an overdue check could mean the record is within the deadline or that the intended check had no usable date. It takes the source value and a separate diagnostic to tell those apart.

One careful design writes a separate message for each important outcome. An empty request slot can remain unmarked. A real Pending request with a text or missing date becomes Check deadline. A valid due date before the cutoff becomes Overdue. An ordinary future or equal date can be Within plan. The viewer then knows which records are actionable and which data must be clarified before taking action.

3. Lab. Flag pending, overdue and high-quote records

Goal. Create a conditional formatting rule across a worksheet row, prove its result with an independent helper, and then examine an overlapping condition. Use a blank sheet with the following headers and inputs in A1:E9. Enter the dates using DATE in the valid rows, then apply a readable date format. Leave the shown blank cells blank. For the Media kit row, enter the date string using an apostrophe so it is text. H1 is Review date and H2 is =DATE(2026,11,20).

Fictional film-club requests with a fixed review date
Request IDRequestDue inputStatusQuote (INR)
S-101Readers10-Nov-2026Complete950
S-102Projector17-Nov-2026Pending2600
S-103Backdrop20-Nov-2026Pending2000
S-104Food18-Nov-2026Cancelled3100
S-105PrintsPending800
S-106Media kit'2026-11-18Pending1400
Unused row19-Nov-2026Pending2100
S-108Sound23-Nov-2026Pending2200

Build the rule in five verified stages

  1. Check the actual inputs

    Use =ISNUMBER(C3) in a spare cell and expect TRUE. Use =ISNUMBER(C7) and expect FALSE because the Media kit due value was entered as text. In H2 read the fixed review date and check it is numeric. Make sure the request ID for the unused row stays blank even though the other columns show test data.

  2. Calculate the independent Boolean results

    Put Overdue?, High quote? and Cancelled? in I1:K1. Enter the next block's formulas into row 2 and fill through row 9. Only S-102 should return TRUE for Overdue. The second helper returns TRUE for S-102, S-104 and S-108. The third finds S-104 only. Read the false cases at the exact date and quote boundary.

  3. Apply the rule from its first selected cell

    Starting at A2, select A2:E9. In the Conditional Formatting menu create a New Rule and choose the formula option where available. Enter the Overdue formula from I2. Choose a readable amber fill. Check that the whole S-102 request row gets the intended format. Read the helper to confirm you did not accidentally highlight row 4 or apply a formula one row off.

  4. Add a second rule and inspect priority

    Add the High quote formula from J2 on the same scope with a different light fill. Inspect the rules in Manage Rules. Put Overdue above High quote, with no Stop If True at first. S-102 meets both tests. If the two rules assign different fills, the higher priority conflicting fill controls the display. A high quote row that does not meet the overdue condition can still show the other fill.

  5. Show two independent facts or stop them intentionally

    For a readable combined view, change High quote to a bold font or border instead of a conflicting fill. With neither rule stopping evaluation, the S-102 row can show the overdue fill and high quote cue together. Add the Cancelled formula above both with a subdued format. Test Stop If True on the Cancelled rule in a supported desktop edition. S-104 should keep the cancellation styling and stop lower formatting from applying when that option is enabled.

I2 =IFERROR(AND($A2<>"",$D2="Pending",ISNUMBER($C2),ISNUMBER($H$2),$C2<$H$2),FALSE)
J2 =IFERROR(AND($A2<>"",ISNUMBER($E2),$E2>2000),FALSE)
K2 =IFERROR(AND($A2<>"",$D2="Cancelled"),FALSE)

Check the first and last references. I9 should read A9, D9 and C9, and the same H2. The chosen condition checks a strictly earlier date. S-103 is exactly 20 November and stays outside the overdue fill. Its 2000 quote is at the strict greater-than boundary and stays outside the high-quote rule too. If the contract says 2000 and above, change the operator deliberately and test that exact observation.

Stopping lower rules changes the styling. The numeric amount on S-104 still exists and J5 remains TRUE, even if you suppress the visible high-quote cue on cancelled rows. For a contract that should count only active high quote work, put the active-state requirement into the report calculation. No one should need to infer a number from which style happened to win in a priority conflict.

Keep an exception label beside a visual that can be quiet

Put Deadline check in L1 in a practice copy. Enter =IFERROR(IF($A2="","",IF($D2<>"Pending","Not pending",IF(AND(ISNUMBER($C2),ISNUMBER($H$2)),IF($C2<$H$2,"Overdue","Within plan"),"Check deadline"))),"Check source") in L2 and fill down. The lab intentionally gives two pending rows missing a usable date. They should read Check deadline. A row with no identifier leaves the label empty. Complete or Cancelled gives Not pending. The result can support a filter regardless of which styles are active elsewhere.

Read the flag and value together. A record whose deadline is typed as text may look valid in the worksheet, especially when the desired format uses the same characters. The diagnostic distinguishes that type problem from a real date. If the genuine deadline is confirmed to be 18 November, convert it deliberately on a copy. That row now joins S-102 as a past date with Pending status. You have changed a verified input, which is different from changing the styling so the row appears overdue.

4. Lab. Compare every count against its own column's target

Goal. Change the meaning of the reference movement. This time we compare one worksheet cell at a time with a target in the same column. Different activities have different targets in different periods. A single fixed due date would be wrong for this job. Use the following fixed inputs on a blank sheet. Leave the row-5 separator blank and type the targets in B6:D6.

Counts in B2:D4 and corresponding targets in B6:D6
DeskEarly countMidday countLate count
Library91215
Gym101520
Hall131423
Target (row 6)101520
  1. Write the comparison for the first cell. Consider B2, the top-left of the formatting range. Its 9 should be compared with B6, the early target of 10. An expression for this cell is =IFERROR(AND(ISNUMBER(B2),ISNUMBER(B$6),B2<B$6),FALSE). It highlights strictly below the target. You could also choose a different policy such as at or below. Here equality qualifies as meeting the target.
  2. Follow a copy across and down. Move the comparison one step right and the current value becomes C2 while the target becomes C6. Move down from there and the current value becomes C3 while the target stays C6. The dollar sign is deliberately before row 6, while the target column can move. Both details matter.
  3. Test it as an independent grid. In B9 enter the formula as written and fill it right through D9 then down through row 11. Each helper inspects the source cell seven rows above: B9 tests B2, B10 tests B3, B11 tests B4. Check that all three Library flags are TRUE, all Gym flags are FALSE and only Hall's midday flag is TRUE. This exercise separates the rule calculation from its visual effect.
  4. Apply and compare the output. In the input grid select B2:D4 starting at B2 and add a formula conditional format with the exact same expression from B9. Choose a visible fill. Check precisely B2, C2, D2 and C4. Avoid applying the rule to the target row. If your test has a problem, read the helper expression for the offending coordinate before widening the selection.
  5. Try one known wrong reference. Create a separate copy and replace B$6 in the rule with $B$6. Every cell now compares against 10. Some midday and late values incorrectly stop being marked. Restore B$6 and inspect C4. Its real condition is 14 below 15, so it is marked under the intended rule.

The source cell reference B2 remains fully relative here. You want each target to check its own data value. If you wrote $B2 for that reference, every target on the same row would check the early count. That could produce a strange pattern where all periods respond to the same recorded count. Before writing a dollar sign, decide what should stay and what should move for the operation in that direction.

In the two-dimensional count grid, B2 compares to B6, C2 compares to C6, and D2 compares to D6. The target column moves with each value but its row remains 6.
A mixed reference can fix the target row while allowing the comparison to follow each column.

Inspect a fixed review boundary and a variable column together

What would happen if the midday target changes from 15 to 14? Library at 12 would still be marked. For Hall, the original 14 would equal the target and no longer be marked. None of the early or late comparisons should be affected in the intended rule. This is an important control. It proves the reference is not only working on the original numbers but also responds correctly when one assumption changes.

Now consider an omitted target in a copy. The helper returns FALSE on that column because the test requires a numeric target. You may want another documentation line saying No target supplied. Mention it in the sheet and retain the input data. Otherwise the absence of a highlight could be interpreted as every cell meeting the target. The real condition is only evaluated once useful inputs exist.

5. Adapt the rule to another practical question

Highlight records that match a selected field value

In the request lab choose one row label such as Projector and put it in H3, with a description in an adjacent cell. Try =IFERROR(AND($A2<>"",$H$3<>"",$B2=$H$3),FALSE) across A2:E9 in a practice copy. With H3 set to Projector, only S-102 should match. Set it to Sound and check that the highlighted row moves to S-108. Clear H3 and expect no row to be marked by this formula. The comparison uses a fixed selection input and a moving source label.

A dropdown for H3 can provide controlled choices. This highlight does not filter or isolate records by itself. If the result is meant to become an exported list, use a separate filter or formula that actually returns the matching rows. This exercise is useful for making the chosen record easier to spot while the rest of the list stays visible. Use the text label and original record IDs so the intended row can also be found without colour.

Distinguish an AND condition from an OR condition with a comparison

Return to the lab and focus on two existing facts. S-102 is Pending and has a quote greater than 2000. S-104 has a high quote and is Cancelled. S-108 is Pending with a high quote, but its deadline is still in the future. A rule for pending and high quote should mark S-102 and S-108. A rule for overdue or high quote could include S-104 too. If you simply change AND to OR in a larger expression, guard tests like nonblank ID might also become independent routes to TRUE. Assemble the common requirements outside the OR group.

For example, with the existing helper results use =AND($A2<>"",OR($I2,$J2)) as a new practice expression. It requires a record and accepts either of the two flags. Verify its results for S-102, S-104 and S-108. If cancelled rows should be excluded, add a separate condition on D and test S-104 again. Good grouping keeps the actual workflow requirement visible to the next person who reads the formula.

Check two common patterns without copying them blindly

  • Calendar day groups. For a numeric date, WEEKDAY with return type 2 numbers Monday through Sunday from 1 to 7. A result greater than 5 selects weekends. Guard for an appropriate numeric input and test a known Saturday and Monday. A numeric true date and a text date may look the same.
  • Banding rows for readability. A rule based on MOD and ROW can distinguish alternating sheet row numbers. That creates a visual pattern and does not carry a business state. A table style can be simpler for ordinary banding. Check whether a sorted or filtered view should keep a particular banding convention.
  • Group-specific comparisons. If an order must be compared with the average for its own team, use a documented group measure and bounded ranges. Verify the member rows separately and handle groups with no valid observations. A global average would answer another question.

Consider calculating the group baseline in a small summary area first. One well-labelled mean per group is easier to inspect and reuse than repeating an entire calculation over a full column inside every visual rule. If you do use a formula within Conditional Formatting, bound the ranges to the actual data and test response time on a representative practice copy. Smaller, visible calculations also simplify debugging when source groups are reclassified.

6. Diagnose a rule without guessing from its colours

  1. Check the cell and its type. A date can be text, a currency label can be a string, and a missing reference can be an error. Open the stored value and evaluate an independent helper on the first suspect row.
  2. Check the first target. The formula should be written for the range's starting context. Verify the visible selection and actual Applies To address. Change one anchor at a time.
  3. Read down and across. Compare a true record with the row above or below it. Walk the formula's references horizontally if only one cell per row changes colour. Walk vertically if every row reacts to the first one.
  4. Check overlapping formatting. A higher rule can control a conflicting fill while lower rules still set another property. An applicable Stop If True rule can suppress lower rules. Check its setting and the rule order on a test case with two true conditions.
  5. Test one added row. Make it an obvious true case in a workbook copy. Check that the formula first holds and the target actually includes the new record. A visual cue that never reaches the new rows cannot guide the new intake.

When moving or copying a range, a formatting rule can be copied with adjusted references or create additional rules. Inspect the actual saved definition for the new cells. Do not repair a misaligned rule by manually painting the current rows. A manual fill can remain after the stored condition changes. Keep either a suitable formula rule or a plain output message that the recipient knows how to verify.

Check edition support before expecting the same dialog on Windows, Mac or the web. The current web instructions include a conditional-formatting pane with a Formula rule type in supported builds. Menu locations and advanced controls can differ. Use the helper expressions to verify the core logic before checking how it looks on each viewing device.

Move the report date and predict which rows qualify first

The first lab uses a fixed 20 November date so the group can reproduce the same result. In a copy change H2 to =DATE(2026,11,24). Before doing so, calculate which pending requests now have genuine dates before that new boundary. S-102 still qualifies, S-103 now has a date earlier than the review, and S-108 becomes overdue because it was due 23 November. S-104 stays out because it is Cancelled. S-105 and S-106 still need deadline review. Nothing about the date shift fixes those two inputs.

Check =COUNTIF(I2:I9,TRUE) under both review dates. The result changes from 1 to 3. Change the date back and see whether the original count returns. This is a test of the absolute shared cutoff reference. If the first row responds and lower rows do not, inspect the copied formulas to ensure they still read H2. If a date cell has become text in your copy, the helper's type check will suppress qualification. Fix the input only after confirming the intended date.

You can make the report's cutoff a separate validated date input, and add a visible label when H2 is empty. A blank cutoff that silently switches every flag to false could look like a successful cleanup. Place the selected review date in the report heading or near the data so recipients know which date was in effect. Treat updates to earlier reports as revisions rather than relying on a workbook that always shows today.

Try a bounded group baseline on the existing quote rows

Set H4 to Pending quote average and enter =AVERAGEIFS($E$2:$E$9,$D$2:$D$9,"Pending",$A$2:$A$9,"<>") in H5. The eligible rows have both Pending status and a nonblank request ID. The unused row's 2100 is excluded because it has no request ID. Five quoted amounts are eligible and total 9000, so the expected mean is 1800. This comparison includes Pending rows with missing or mistyped deadlines because the rule is about quoted amount, not overdue status.

In a copy create a review rule for the Pending rows whose quoted amount is above that group mean. Use =IFERROR(AND($A2<>"",$D2="Pending",ISNUMBER($E2),ISNUMBER($H$5),$E2>$H$5),FALSE) for the same A2:E9 range. The flagged records should be S-102, S-103 and S-108. S-103 was exactly 2000 and therefore did not satisfy the separate high-quote policy from the first lab. It still qualifies under the comparison with 1800. Both answers can be useful if their labels tell you which question the rule asked.

The shared group average lives in one formula with a visible value, which makes it easier to diagnose than rebuilding the group's summary in every evaluated cell. If you remove all Pending records in a copy, the average may produce a division error since there is no qualifying group. Add a simple No pending quotes label after confirming the count. A guarded format may stay off, but an absent group deserves a clear state when a reader is expecting new data.

Prove one pattern before rolling it out across a whole sheet

Try the weekday case on a spare three-row range. Put numeric 21 November 2026 and 23 November 2026 in C2 and C3 using DATE, and leave C4 blank. Put temporary IDs in A2:A4. Use =IFERROR(AND($A2<>"",ISNUMBER($C2),WEEKDAY($C2,2)>5),FALSE) as an ordinary worksheet helper and copy it down. Expect TRUE on Saturday the 21st, FALSE on Monday the 23rd and FALSE on the blank date. With return type 2, Saturday yields 6 and Monday yields 1. The weekend threshold is tied to that numbering choice.

After the helper results are right, apply it as a rule for the three matching rows. See that the date cell's displayed weekday remains readable. If you need to check whether a site actually closes that day, a weekend rule is only the calendar portion of the policy. The holiday or exception calendar belongs in a separate source. A TRUE result in the teaching sheet means weekend under the stated definition.

Show colleagues how to inspect formatting without losing evidence

Tell a colleague the start of the range, the column that remains locked and the shared cutoff location. Then give them one row that must be highlighted, one equal boundary that must stay outside and one error or incomplete row with a separate diagnosis. They should be able to request a change without rewriting every rule. Labels such as Overdue, Check deadline and Review cost allow them to compare results in a spreadsheet, a printout and a phone view.

Save a test copy before moving columns or joining sections. Formula references can adjust when cells are inserted, cut or pasted, and copied formatting may create additional rules. Use the manager to check the final ranges. For a workbook with repeated branches, compare two physical positions with different results. A correct first row is insufficient evidence that the operation also worked for the last row and for later columns. Repeat the same data tests after you change a rule or destination, and keep the original timing basis with the report.

Compare changes in condition and changes in scope

If a policy applies only to the quote column, keep the same qualifying condition but change the target cells to E2:E9. The fill now paints each visible quote rather than all five fields in its row. In a practice copy of the rule, compare that result with the whole-row version. Both can read the same fixed-column deadline and status. The selected range answers which cells look different. The expression answers which record qualifies.

A weekday rule can likewise shade the calendar field to draw attention to scheduling, while an overdue rule can mark a row to show which request a person needs to follow up. Give the two rules different purposes and test their overlap. If they share the same cells and conflicting styles, choose a priority deliberately. Use a compact summary report when many related rules crowd the entry grid.

A formatting rule is part of the workbook's logic, even when users only see a fill. Keep an acceptance record with the addresses and two confirmed cases. If a copied template uses the wrong scope, the next editor can compare its behaviour to the original rather than recreating it from memory. When they make a deliberate change, have them rerun both the valid and invalid examples. Looking only at an apparent improvement in one row can hide a new problem in the next one.

To verify your final setup, hide the colours in a practice copy and ask someone to reproduce the result using the helper statuses. If they can identify the same records, the style is supporting the decision without carrying its only explanation.

Continue through the existing Excel Task Hub. In each new problem, write the first Applies To address and the two cell references that should change before testing the format.

7. Interview questions with worked answers

How would you highlight an entire overdue row?

Choose the record range. Place the status and deadline references in fixed columns with relative row numbers. Keep the shared review date absolute. Check that the ID and valid deadline are present and that the date is before the boundary under the right status.

Why does the whole sheet look at the first row only?

One possibility is an absolute row, such as a reference to $D$2. The formula then reads the same status in every evaluated record. Fix just the column for a single-status-field test and verify different rows.

Which reference moves with its column but keeps its row?

B$6 moves to C$6 when evaluated one target column to the right. It stays on row 6. That is useful for a comparison against column-specific targets laid out across the same header row.

What can happen if two true rules choose different fills?

The higher-priority conflicting style takes effect. Other nonconflicting styles may combine. Stop If True can stop lower applicable rules on a supported rule. Neither decision changes the stored amount or underlying helper results.

How would you troubleshoot a date that appears overdue but has no highlight?

Check whether it is a real date, whether its row is included, and whether its status and ID meet the rest of the condition. Evaluate an identical helper and inspect other styles only after confirming the truth value.

8. Predict the outcome before opening the explanation

  1. Which column should remain fixed when an entire request row reads Status in D?

    Answer and reasoning

    Fix column D and let the row move, as in $D2 for a range starting at row 2.

  2. Does the Pending request due on the review date count as overdue under an earlier-than rule?

    Answer and reasoning

    No. Equal is outside the strict comparison. Change the policy only if its wording actually includes the boundary.

  3. Why might a blank date be risky in a raw numeric comparison?

    Answer and reasoning

    It can be treated as zero in a comparison, which could look like an old date. Check for a usable number and show an explicit missing-data status.

  4. What happens when Hall's midday target changes from 15 to 14?

    Answer and reasoning

    Hall has 14, so it equals the target and is no longer below. The other column targets remain the same.

  5. Does Stop If True clear the high quote value from a Cancelled row?

    Answer and reasoning

    No. It suppresses lower qualifying formatting rules where applied. The quote and Boolean helper remain available.

9. Six decisions for the next rule

  • Start with TRUE or FALSE

    Write the condition in a helper and verify different rows before applying colour.

  • Match the range origin

    Read the first target and formula together. An off-by-one origin can flag the wrong row.

  • Fix only the part that must stay

    Use a fixed field column for row conditions or a fixed target row for a grid that changes by column.

  • Guard incomplete data

    Missing and text values can look valid. Check types and give exceptions a plain label.

  • Know which rule wins

    Compare priority and conflicting properties. Test two true rules together and read the underlying helper values.

  • Check the next record

    A known true and known false row at the end of the range make it easier to verify coverage after growth.

Microsoft references