keepcalculator

06 Numbers and Powers

Conditional Formatting with One Input

Card No. 06·49512 · Updated · Standard formula, shown below

The calculator on this card is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

Conditional formatting with a single variable input lets you highlight cells based on one changing value, such as a threshold, a target, or a drop-down selection. You enter that one value in a cell (or a control), and the formatting rules automatically update to match it. This is a common Excel and Google Sheets technique for dashboards, reports, and data reviews.

Formula

The calculator works on a fixed range of 10 cells (A1:A10). You enter a threshold value t. The formula counts how many cells are above t and how many are below t. The percentage above is simply count_above / 10 × 100. In a real spreadsheet, you would use conditional formatting rules that reference the threshold cell directly, e.g., =A1>$B$1 applied to the range A1:A10.

Worked Example

Suppose you have 10 sales figures in A1:A10: 5, 12, 8, 15, 3, 10, 7, 14, 6, 11. You set the threshold t = 10. The calculator counts cells strictly greater than 10: 12, 15, 14, 11 → 4 cells. Cells strictly less than 10: 5, 8, 3, 7, 6 → 5 cells. The cell equal to 10 is ignored. Percent above = 4/10 × 100 = 40%. The calculator shows 4, 5, and 40.0%.

Why Use a Single Variable Input?

Most conditional formatting rules use fixed values hard-coded into the rule. For example, you might highlight all cells above 10. But when that number changes, you have to edit the rule manually. By putting the threshold in a cell and referencing it in the rule, you can change the threshold without touching the formatting dialog. This is especially useful for:

  • Interactive dashboards where a user types a target.
  • Comparing actuals against a moving benchmark.
  • Highlighting outliers above or below a dynamic cutoff.
  • Creating heat maps that adapt to a selected percentile.

How to Set It Up in Excel and Google Sheets

The steps are similar in both applications. In Excel:

  1. Select the data range (e.g., A1:A10).
  2. Go to Home → Conditional Formatting → New Rule.
  3. Choose “Use a formula to determine which cells to format”.
  4. Enter a formula like =A1>$B$1 where B1 holds your threshold.
  5. Set the format (fill, font, etc.) and click OK.

In Google Sheets:

  1. Select the range (e.g., A1:A10).
  2. Go to Format → Conditional formatting.
  3. Under “Format cells if”, choose “Custom formula is”.
  4. Enter =A1>$B$1 and set the formatting style.
  5. Click Done.

The key is the dollar sign before the column and row ($B$1) to lock the reference to the threshold cell. Without it, the rule would shift as it applies to each cell.

Common Mistakes and Pitfalls

  • Relative vs absolute references: Using B1 instead of $B$1 causes the rule to check a different cell for each row, breaking the logic.
  • Applying to the wrong range: The range you select before creating the rule must match the formula’s relative reference. If you select A1:A10, the formula should start with A1, not A2.
  • Mixing text and numbers: If the threshold cell contains text (like “10” with a space), comparisons may fail. Ensure it’s numeric.
  • Ignoring equality: Decide whether to use > or >=. The calculator uses strict > and <. If you want to include the threshold value, use >= and <=.
  • Hidden rows: Conditional formatting still applies to hidden or filtered rows, which may produce unexpected highlights.

Choosing the Right Comparison Operator

Your choice of operator changes the meaning of “above” and “below”. For a threshold of 10:

  • >10 highlights values strictly greater than 10.
  • >=10 highlights 10 and above.
  • <10 highlights values strictly less than 10.
  • <=10 highlights 10 and below.

In dashboards, it’s common to use two rules: one for values above the threshold (green) and one for values below (red). The calculator’s count and percentage help you verify the rule is working as intended.

Limitations and Alternatives

Conditional formatting with one variable input works best for a single cutoff. If you need multiple thresholds (e.g., low, medium, high), you can add more input cells and use nested formulas like =AND(A1>$B$1, A1<$C$1). For color scales based on percentiles, you can use built-in percentile rules, but those do not accept a dynamic input. A more advanced alternative is to use a form control (like a spinner or slider) linked to the threshold cell, making the dashboard interactive without typing.

Frequently Asked Questions

Can I use a drop-down list as the variable input?

Yes. Create a data validation list in the threshold cell. The conditional formatting rule will automatically update when you select a new value from the drop-down. This is a popular way to switch between different scenarios.

Why is my conditional formatting not updating when I change the input?

Make sure the formula references the input cell with absolute references ($B$1). Also check that calculation is set to automatic (Excel: Formulas → Calculation Options → Automatic). If you’re using a volatile function like RAND, it may recalculate only on change.

Can I use this technique on an entire column?

Yes. Select the whole column (e.g., A:A) and use a formula like =A1>$B$1. The rule will apply to every cell in the column, but ensure the formula starts with the first row of your data, not a header.

What if I want to highlight the entire row based on a single cell?

Use a formula that references the row’s key cell with a mixed reference. For example, to highlight rows where B is above the threshold, select A1:D10 and use =B$1>$E$1. The dollar before the row number locks the row, while the column can change.

Does this work in Google Sheets on mobile?

Yes, Google Sheets mobile supports conditional formatting, but editing rules on a small screen can be cumbersome. The same formula syntax works, but you may need to switch to desktop for complex rules.

Can I use this to highlight dates before a certain date?

Yes. Put a date in the threshold cell and use a formula like =A1<$B$1. Ensure both cells are formatted as dates. The comparison works because dates are stored as numbers.

Related

Formula used
in t | Threshold | number | 10 | 0 | 10000
out count_above | Cells above threshold | count | sum(if(A1:A10>t,1,0)) | 0
out count_below | Cells below threshold | count | sum(if(A1:A10

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →